ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2025-12-07 03:15:32
Exec Total Coverage
Lines: 3114 8817 35.3%
Functions: 84 313 26.8%
Branches: 2716 7799 34.8%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/pal_tables.h"
10 #include "base/version.h"
11 #include "base/zapp.h"
12 #include "base/zdefs.h"
13 #include "dialog/info.h"
14 #include "gui/jwin.h"
15 #include "metadata/metadata.h"
16
17 #include "base/qrs.h"
18 #include "base/dmap.h"
19 #include "base/packfile.h"
20 #include "base/cpool.h"
21 #include "base/autocombo.h"
22 #include "base/gui.h"
23 #include "base/msgstr.h"
24 #include "zc/zelda.h"
25 #include "zq/zq_class.h"
26 #include "zq/render.h"
27 #include "zq/render_map_view.h"
28 #include "zq/zq_misc.h"
29 #include "zq/zquest.h"
30 #include "base/qst.h"
31 #include "base/colors.h"
32 #include "tiles.h"
33 #include "base/zsys.h"
34 #include "sprite.h"
35 #include "items.h"
36 #include "zc/zc_sys.h"
37 #include "base/md5.h"
38 #include "hero_tiles.h"
39 #include "subscr.h"
40 #include "zq/zq_strings.h"
41 #include "zq/zq_subscr.h"
42 #include "zc/ffscript.h"
43 #include "base/util.h"
44 #include "zq/zq_files.h"
45 #include "dialog/alert.h"
46 #include "slopes.h"
47 #include "drawing.h"
48 #include "zinfo.h"
49 #include "zq/render_minimap.h"
50 #include "base/mapscr.h"
51 #include "iter.h"
52 #include <fmt/format.h>
53 #include <filesystem>
54
55 #ifdef __EMSCRIPTEN__
56 #include "base/emscripten_utils.h"
57 #endif
58
59 namespace fs = std::filesystem;
60
61 using namespace util;
62
63 extern uint8_t ViewLayer3BG, ViewLayer2BG;
64 extern int32_t LayerDitherBG, LayerDitherSz;
65 extern bool NoHighlightLayer0;
66
67 using std::string;
68 using std::pair;
69
70 #define COLOR_SOLID vc(4)
71 #define COLOR_SLOPE vc(13)
72 #define COLOR_LADDER vc(6)
73 //#define COLOR_EFFECT vc(10)
74
75 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
76 extern char msgbuf[MSG_NEW_SIZE*8];
77
78 extern string zScript;
79
80 12 zmap Map;
81 int32_t prv_mode=0;
82
83 bool save_warn=true;
84
85 int32_t COMBOPOS(int32_t x, int32_t y)
86 {
87 return (((y) & 0xF0) + ((x) >> 4));
88 }
89 int32_t COMBOPOS_B(int32_t x, int32_t y)
90 {
91 if(unsigned(x) >= 256 || unsigned(y) >= 176)
92 return -1;
93 return COMBOPOS(x,y);
94 }
95 int32_t COMBOX(int32_t pos)
96 {
97 return ((pos) % 16 * 16);
98 }
99 int32_t COMBOY(int32_t pos)
100 {
101 return ((pos) & 0xF0);
102 }
103
104 void reset_dmap(int32_t index)
105 {
106 bound(index,0,MAXDMAPS-1);
107 DMaps[index].clear();
108 DMaps[index].title = "";
109 sprintf(DMaps[index].intro, " ");
110 }
111
112 void reset_dmaps()
113 {
114 for(int32_t i=0; i<MAXDMAPS; i++)
115 reset_dmap(i);
116 }
117
118 void truncate_dmap_title(std::string& title)
119 {
120 title.resize(21, ' ');
121 }
122
123 mapscr* zmap::get_prvscr()
124 {
125 return &prvscr;
126 }
127
128
7/12
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 138 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 115 times.
✓ Branch 7 taken 23 times.
✓ Branch 8 taken 23 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 23 times.
✗ Branch 11 not taken.
138 zmap::zmap()
129 {
130 23 can_paste=false;
131 23 prv_cmbcycle=0;
132 23 prv_advance=0;
133 23 prv_freeze=0;
134 23 copyffc=-1;
135
136 23 memset(scrpos, 0, sizeof(scrpos));
137 23 memset(scrview, 0, sizeof(scrview));
138 23 screens=NULL;
139 23 prv_time=0;
140 23 prv_scr=0;
141 23 prv_map=0;
142 23 copyscr=0;
143 23 cursor={};
144 copymap=0;
145 layer_target_map = 0;
146 layer_target_scr = 0;
147 layer_target_multiple = 0;
148 }
149
150 11 void zmap::clear()
151 {
152
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 *this = zmap();
153 11 }
154 void zmap::force_refr_pointer()
155 {
156 if(unsigned(cursor.map) > map_count || (cursor.map*MAPSCRS > TheMaps.size()))
157 screens = nullptr;
158 else screens = &TheMaps[cursor.map*MAPSCRS];
159 }
160 bool zmap::CanUndo()
161 {
162 return input_undo_stack.size() > 0;
163 }
164 bool zmap::CanRedo()
165 {
166 return input_redo_stack.size() > 0;
167 }
168 bool zmap::CanPaste()
169 {
170 return can_paste;
171 }
172 int32_t zmap::CopyScr()
173 {
174 return (copymap<<8)+copyscr;
175 }
176 int32_t zmap::getCopyFFC()
177 {
178 return copyffc;
179 }
180 set_ffc_command::data_t zmap::getCopyFFCData()
181 {
182 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
183 }
184 67 int32_t zmap::getMapCount()
185 {
186 67 return map_count;
187 }
188 int32_t zmap::getLayerTargetMap()
189 {
190 return layer_target_map;
191 }
192 int32_t zmap::getLayerTargetScr()
193 {
194 return layer_target_scr;
195 }
196 int32_t zmap::getLayerTargetMultiple()
197 {
198 return layer_target_multiple;
199 }
200 bool zmap::isDungeon(int32_t scr)
201 {
202 for(int32_t i=0; i<4; i++)
203 {
204 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
205 {
206 return false;
207 }
208 }
209
210 return true;
211 }
212
213 bool zmap::clearall(bool validate)
214 {
215 Color=0;
216 char tbuf[10];
217
218 if((header.templatepath[0]!=0)&&validate)
219 {
220 if(!valid_zqt(header.templatepath))
221 {
222 jwin_alert("Error","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
223 return false;
224 }
225 }
226
227 for(int32_t i=0; i<map_count; i++)
228 {
229 setCurrMap(i);
230 sprintf(tbuf, "%d", i);
231 clearmap(true);
232 }
233
234 setCurrMap(0);
235 return true;
236 }
237
238 bool zmap::reset_templates(bool validate)
239 {
240 //why are we doing this?
241 if(colordata==NULL)
242 {
243 return false;
244 }
245
246 //int32_t ret;
247 word version, build, dummy, sversion=0;
248 byte dummyc;
249 word dummyw;
250 //int32_t section_size;
251 word temp_map_count;
252 mapscr temp_mapscr;
253 PACKFILE *f=NULL;
254
255 // setPackfilePassword(datapwd);
256 f=open_quest_template(&header, "modules/classic/default.qst", validate);
257 get_version_and_build(f, &version, &build);
258
259 if(!find_section(f, ID_MAPS))
260 {
261 // setPackfilePassword(NULL);
262 return false;
263 }
264
265 //section version info
266 if(!p_igetw(&sversion,f))
267 {
268 return false;
269 }
270
271 if(!p_igetw(&dummy,f))
272 {
273 return false;
274 }
275
276 //section size
277 dword dummy_size;
278 if(!p_igetl(&dummy_size,f))
279 {
280 return false;
281 }
282
283 //finally... section data
284 if(!p_igetw(&temp_map_count,f))
285 {
286 return false;
287 }
288
289 if(version>12)
290 {
291 if(!p_getc(&dummyc,f))
292 return qe_invalid;
293
294 if(!p_getc(&dummyc,f))
295 return qe_invalid;
296
297 if(!p_igetw(&dummyw,f))
298 return qe_invalid;
299
300 if(!p_igetw(&dummyw,f))
301 return qe_invalid;
302
303 if(!p_igetw(&dummyw,f))
304 return qe_invalid;
305
306 if(!p_igetw(&dummyw,f))
307 return qe_invalid;
308
309 if(!p_igetw(&dummyw,f))
310 return qe_invalid;
311
312 if(!p_igetw(&dummyw,f))
313 return qe_invalid;
314
315 if(!p_igetw(&dummyw,f))
316 return qe_invalid;
317
318 if(!p_igetw(&dummyw,f))
319 return qe_invalid;
320
321 if(!p_igetw(&dummyw,f))
322 return qe_invalid;
323
324 if(!p_igetw(&dummyw,f))
325 return qe_invalid;
326
327 if(!p_getc(&dummyc,f))
328 return qe_invalid;
329
330 if(!p_getc(&dummyc,f))
331 return qe_invalid;
332 }
333
334 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
335 {
336 readmapscreen(f, &header, &temp_mapscr, sversion);
337 }
338
339 readmapscreen(f, &header, &TheMaps[128], sversion);
340 readmapscreen(f, &header, &TheMaps[129], sversion);
341
342 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
343 {
344 readmapscreen(f, &header, &temp_mapscr, sversion);
345 }
346
347 if(version>12)
348 {
349 if(!p_getc(&dummyc,f))
350 return qe_invalid;
351
352 if(!p_getc(&dummyc,f))
353 return qe_invalid;
354
355 if(!p_igetw(&dummyw,f))
356 return qe_invalid;
357
358 if(!p_igetw(&dummyw,f))
359 return qe_invalid;
360
361 if(!p_igetw(&dummyw,f))
362 return qe_invalid;
363
364 if(!p_igetw(&dummyw,f))
365 return qe_invalid;
366
367 if(!p_igetw(&dummyw,f))
368 return qe_invalid;
369
370 if(!p_igetw(&dummyw,f))
371 return qe_invalid;
372
373 if(!p_igetw(&dummyw,f))
374 return qe_invalid;
375
376 if(!p_igetw(&dummyw,f))
377 return qe_invalid;
378
379 if(!p_igetw(&dummyw,f))
380 return qe_invalid;
381
382 if(!p_igetw(&dummyw,f))
383 return qe_invalid;
384
385 if(!p_getc(&dummyc,f))
386 return qe_invalid;
387
388 if(!p_getc(&dummyc,f))
389 return qe_invalid;
390 }
391
392 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
393 {
394 readmapscreen(f, &header, &temp_mapscr, sversion);
395 }
396
397 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
398 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
399
400 pack_fclose(f);
401 clear_quest_tmpfile();
402
403 return true;
404 }
405
406 bool zmap::clearmap(bool newquest)
407 {
408 if(cursor.map<map_count)
409 {
410 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
411 {
412 clearscr(i);
413 }
414
415 setCurrScr(0);
416
417 if(newquest)
418 {
419 if(!reset_templates(false))
420 {
421 jwin_alert("Error","Error resetting","template screens.",NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
422 }
423 }
424 }
425
426 return true;
427 }
428
429 MapCursor zmap::getCursor() const
430 {
431 return cursor;
432 }
433
434 11 void zmap::setCursor(MapCursor new_cursor)
435 {
436
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11 if (cursor == new_cursor && screens)
437 return;
438
439
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (screens)
440 pushCursorToHistory(std::move(cursor));
441 11 cursor = std::move(new_cursor);
442
443
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!screens) Color = -1;
444 11 screens = &TheMaps[cursor.map*MAPSCRS];
445
446 11 refresh_color();
447 11 setlayertarget();
448 11 reset_combo_animations2();
449 11 mmap_mark_dirty();
450 11 regions_mark_dirty();
451 11 }
452
453 void zmap::pushCursorToHistory(MapCursor cursor)
454 {
455 if (cursor_history_enabled)
456 {
457 cursor_undo_stack.push_back(std::move(cursor));
458 cursor_redo_stack = {};
459 CapCursorHistory();
460 }
461 }
462
463 bool zmap::isValidPosition(ComboPosition pos) const
464 {
465 return pos.is_valid(cursor);
466 }
467
468 int zmap::getScreenForPosition(ComboPosition pos) const
469 {
470 return cursor.viewscr + pos.screen_offset();
471 }
472
473 mapscr* zmap::CurrScr()
474 {
475 return screens+cursor.screen;
476 }
477 mapscr* zmap::Scr(int32_t scr)
478 {
479 return screens+scr;
480 }
481 mapscr* zmap::Scr(ComboPosition pos)
482 {
483 if (!pos.is_valid(cursor))
484 return nullptr;
485
486 int screen_offset = pos.screen_offset();
487 int screen = cursor.viewscr + screen_offset;
488 return AbsoluteScr(cursor.map, screen);
489 }
490 mapscr* zmap::Scr(ComboPosition pos, int layer)
491 {
492 int map = cursor.map;
493 int screen = cursor.viewscr + pos.screen_offset();
494 if (layer)
495 {
496 mapscr* scr = Map.AbsoluteScr(map, screen);
497 map = scr->layermap[CurrentLayer-1]-1;
498 screen = scr->layerscreen[CurrentLayer-1];
499 }
500
501 return AbsoluteScr(map, screen);
502 }
503 mapscr* zmap::ScrMakeValid(ComboPosition pos, int layer)
504 {
505 mapscr* scr = Scr(pos, layer);
506 if (scr && !(scr->valid&mVALID))
507 {
508 scr->valid |= mVALID;
509 setcolor(Color, scr);
510 }
511 return scr;
512 }
513 mapscr* zmap::AbsoluteScr(int32_t scr)
514 {
515 if(unsigned(scr) >= MAPSCRS*getMapCount())
516 return nullptr;
517 return &TheMaps[scr];
518 }
519 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
520 {
521 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
522 return nullptr;
523 return AbsoluteScr((map*MAPSCRS)+scr);
524 }
525 mapscr* zmap::AbsoluteScrMakeValid(int32_t map, int32_t screen)
526 {
527 mapscr* scr = AbsoluteScr(map, screen);
528 if (scr && !(scr->valid&mVALID))
529 {
530 scr->valid |= mVALID;
531 setcolor(Color, scr);
532 }
533 return scr;
534 }
535 void zmap::set_prvscr(int32_t map, int32_t scr)
536 {
537 prvscr = *get_canonical_scr(map, scr);
538
539 for(int32_t i=0; i<6; i++)
540 {
541 if(prvscr.layermap[i]>0)
542 {
543 prvlayers[i] = *get_canonical_scr(prvscr.layermap[i] - 1, prvscr.layerscreen[i]);
544 }
545 else
546 prvlayers[i].valid = 0;
547 }
548
549 prv_map=map;
550 prv_scr=scr;
551 }
552 92 int32_t zmap::getCurrMap()
553 {
554 92 return cursor.map;
555 }
556 11 void zmap::regions_mark_dirty()
557 {
558 11 regions_dirty = true;
559 11 }
560 void zmap::regions_refresh()
561 {
562 if (!regions_dirty)
563 return;
564
565 regions_dirty = false;
566 region_descriptions.clear();
567
568 current_map_region_ids = Regions[cursor.map].get_all_region_ids();
569 if (!get_all_region_descriptions(region_descriptions, current_map_region_ids))
570 region_descriptions.clear();
571 }
572 const std::vector<region_description>& zmap::get_region_descriptions()
573 {
574 regions_refresh();
575 return region_descriptions;
576 }
577 bool zmap::is_region(int screen)
578 {
579 if (screen < 0 || screen >= 128)
580 return false;
581
582 regions_refresh();
583 return current_map_region_ids[screen];
584 }
585 bool zmap::isDark(int scr)
586 {
587 return (screens[scr].flags&fDARK)!=0;
588 }
589 bool zmap::isValid(int32_t scr)
590 {
591 return (screens[scr].valid&mVALID)!=0;
592 }
593 bool zmap::isValid(int32_t map, int32_t scr)
594 {
595 return (AbsoluteScr(map, scr)->valid&mVALID)!=0;
596 }
597
598 void zmap::setCurrMap(int32_t index)
599 {
600 scrpos[cursor.map] = cursor.screen;
601 scrview[cursor.map] = cursor.viewscr;
602
603 auto new_cursor = cursor;
604 new_cursor.map = bound(index,0,map_count);
605
606 new_cursor.viewscr = scrview[new_cursor.map];
607 new_cursor.setScreen(scrpos[new_cursor.map]);
608 setCursor(std::move(new_cursor));
609 }
610
611 20 int32_t zmap::getCurrScr()
612 {
613 20 return cursor.screen;
614 }
615 void zmap::setCurrScr(int32_t scr)
616 {
617 if (scr == cursor.screen)
618 return;
619
620 auto new_cursor = cursor;
621 new_cursor.setScreen(scr);
622 setCursor(std::move(new_cursor));
623 }
624
625 int32_t zmap::getViewScr()
626 {
627 return cursor.viewscr;
628 }
629
630 void zmap::setViewSize(int32_t size)
631 {
632 auto new_cursor = cursor;
633 new_cursor.setSize(size);
634 setCursor(std::move(new_cursor));
635 }
636
637 1 int32_t zmap::getViewSize()
638 {
639 1 return cursor.size;
640 }
641
642 11 void zmap::setlayertarget()
643 {
644 11 layer_target_map = 0;
645 11 layer_target_multiple = 0;
646
647
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 11 times.
67 for(int32_t m=0; m<getMapCount(); ++m)
648 {
649
2/2
✓ Branch 0 taken 7616 times.
✓ Branch 1 taken 56 times.
7672 for(int32_t s=0; s<MAPSCRS; ++s)
650 {
651 7616 int32_t i=(m*MAPSCRS+s);
652 7616 mapscr *ts=&TheMaps[i];
653
654 // Search through each layer
655
2/2
✓ Branch 0 taken 45696 times.
✓ Branch 1 taken 7616 times.
53312 for(int32_t w=0; w<6; ++w)
656 {
657
3/4
✓ Branch 0 taken 15868 times.
✓ Branch 1 taken 29828 times.
✓ Branch 2 taken 15868 times.
✗ Branch 3 not taken.
45696 if(ts->layerscreen[w]==cursor.screen && (ts->layermap[w]-1)==cursor.map)
658 {
659 if(layer_target_map > 0)
660 {
661 layer_target_multiple += 1;
662 continue;
663 }
664
665 layer_target_map = m+1;
666 layer_target_scr = s;
667 }
668 45696 }
669 7616 }
670 56 }
671 11 }
672
673 11 void zmap::refresh_color()
674 {
675 11 auto color = getcolor();
676
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (Color != color)
677 {
678 11 loadlvlpal(color);
679 11 rebuild_trans_table();
680 11 }
681 11 }
682
683 void zmap::setcolor(int color, mapscr* scr)
684 {
685 if (!scr)
686 scr = CurrScr();
687 scr->valid |= mVALID;
688 scr->color = color;
689
690 refresh_color();
691
692 mmap_mark_dirty();
693 }
694
695 11 int32_t zmap::getcolor()
696 {
697 11 return getcolor(cursor.screen);
698 }
699
700 11 int32_t zmap::getcolor(int screen)
701 {
702
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 mapscr& scr = prv_mode ? prvscr : screens[screen];
703
704
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (scr.valid & mVALID)
705 11 return scr.color;
706
707 return map_infos[cursor.map].autopalette;
708 11 }
709
710 void zmap::resetflags()
711 {
712 byte *di=&(screens[cursor.screen].valid);
713
714 for(int32_t i=1; i<48; i++)
715 {
716 *(di+i)=0;
717 }
718 }
719
720 word zmap::tcmbdat(int32_t pos)
721 {
722 return screens[TEMPLATE].data[pos];
723 }
724
725 word zmap::tcmbcset(int32_t pos)
726 {
727 return screens[TEMPLATE].cset[pos];
728 }
729
730 int32_t zmap::tcmbflag(int32_t pos)
731 {
732 return screens[TEMPLATE].sflag[pos];
733 }
734
735 word zmap::tcmbdat2(int32_t pos)
736 {
737 return screens[TEMPLATE2].data[pos];
738 }
739
740 word zmap::tcmbcset2(int32_t pos)
741 {
742 return screens[TEMPLATE2].cset[pos];
743 }
744
745 int32_t zmap::tcmbflag2(int32_t pos)
746 {
747 return screens[TEMPLATE2].sflag[pos];
748 }
749
750 void zmap::TemplateAll()
751 {
752 StartListCommand();
753 for(int32_t i=0; i<128; i++)
754 {
755 if((screens[i].valid&mVALID) && isDungeon(i))
756 DoTemplateCommand(-1, -1, i);
757 }
758 FinishListCommand();
759 }
760
761 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
762 {
763 if(scr==TEMPLATE)
764 return;
765
766 if(!(screens[scr].valid&mVALID))
767 screens[scr].color=Color;
768
769 screens[scr].valid|=mVALID;
770
771 for(int32_t i=0; i<32; i++)
772 {
773 screens[scr].data[i]=screens[TEMPLATE].data[i];
774 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
775 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
776 }
777
778 for(int32_t i=144; i<176; i++)
779 {
780 screens[scr].data[i]=screens[TEMPLATE].data[i];
781 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
782 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
783 }
784
785 for(int32_t y=2; y<=9; y++)
786 {
787 int32_t j=y<<4;
788 screens[scr].data[j]=screens[TEMPLATE].data[j];
789 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
790 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
791 ++j;
792 screens[scr].data[j]=screens[TEMPLATE].data[j];
793 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
794 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
795 ++j;
796 j+=12;
797 screens[scr].data[j]=screens[TEMPLATE].data[j];
798 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
799 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
800 ++j;
801 screens[scr].data[j]=screens[TEMPLATE].data[j];
802 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
803
804 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
805 ++j;
806 }
807
808 if(floorcombo!=-1)
809 {
810 for(int32_t y=2; y<9; y++)
811 for(int32_t x=2; x<14; x++)
812 {
813 int32_t i=(y<<4)+x;
814 screens[scr].data[i] = floorcombo;
815 screens[scr].cset[i] = floorcset;
816 }
817 }
818
819 for(int32_t i=0; i<4; i++)
820 putdoor(scr,i,screens[scr].door[i]);
821 }
822
823
824 void zmap::clearscr(int32_t scr)
825 {
826 screens[scr].zero_memory();
827 screens[scr].valid=mVERSION;
828 auto const& mapinf = map_infos[cursor.map];
829 for(int q = 0; q < 6; ++q)
830 {
831 auto layer = mapinf.autolayers[q];
832 screens[scr].layermap[q] = layer;
833 screens[scr].layerscreen[q] = layer ? scr : 0;
834 }
835 screens[scr].color = mapinf.autopalette;
836 if (scr == cursor.screen)
837 refresh_color();
838 mmap_mark_dirty();
839 }
840
841 const char *loaderror[] =
842 {
843
844 "OK","File not found","Incomplete data",
845 "Invalid version","Invalid file"
846
847 };
848
849 int32_t zmap::load(const char *path)
850 {
851 PACKFILE *f=pack_fopen_password(path,F_READ, "");
852
853 if(!f)
854 return 1;
855
856
857 int16_t version;
858 byte build;
859
860 //get the version
861 if(!p_igetw(&version,f))
862 {
863 goto file_error;
864 }
865
866 //get the build
867 if(!p_getc(&build,f))
868 {
869 goto file_error;
870 }
871
872 for(int32_t i=0; i<MAPSCRS; i++)
873 {
874 mapscr tmpimportscr;
875 tmpimportscr.zero_memory();
876 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
877 {
878 al_trace("failed zmap::load\n");
879 goto file_error;
880 }
881
882 switch(ImportMapBias)
883 {
884 case 0:
885 *(screens+i) = tmpimportscr;
886 break;
887
888 case 1:
889 if(!(screens[i].valid&mVALID))
890 {
891 *(screens+i) = tmpimportscr;
892 }
893 break;
894
895 case 2:
896 if(tmpimportscr.valid&mVALID)
897 {
898 *(screens+i) = tmpimportscr;
899 }
900 break;
901 }
902 }
903
904
905 pack_fclose(f);
906
907 setCurrScr(0);
908 mmap_mark_dirty();
909 regions_mark_dirty();
910 return 0;
911
912 file_error:
913 pack_fclose(f);
914 clearmap(false);
915 return 2;
916 }
917
918 int32_t zmap::save(const char *path)
919 {
920 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
921
922 if(!f)
923 return 1;
924
925 if(!p_iputw(V_MAPS,f))
926 {
927 pack_fclose(f);
928 return 3;
929 }
930
931 // This was the "build number", but that's totally useless here. Keep this junk byte
932 // so as not to totally break exports between ZC versions.
933 if(!p_putc(0,f))
934 {
935 pack_fclose(f);
936 return 3;
937 }
938
939 for(int32_t i=0; i<MAPSCRS; i++)
940 {
941 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
942 {
943 pack_fclose(f);
944 return 2;
945 }
946 }
947
948 pack_fclose(f);
949 return 0;
950 }
951
952
953 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
954 {
955 // Hookshots can be blocked by solid combos on all 3 ground layers.
956 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
957
958 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
959 return true;
960 if (c->walk&(1<<i))
961 return false;
962
963 for(int32_t k=0; k<2; k++)
964 {
965 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
966
967 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
968 {
969 return false;
970 }
971 }
972
973 return true;
974 }
975
976 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
977 {
978 // Hookshots can be blocked by solid combos on all 3 ground layers.
979 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
980
981 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
982 return true;
983 if (c->walk&(1<<i))
984 return false;
985
986 for(int32_t k=0; k<2; k++)
987 {
988 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
989
990 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
991 {
992 return false;
993 }
994 }
995
996 return true;
997 }
998
999 bool zmap::isstepable(int32_t combo)
1000 {
1001 // This is kind of odd but it's true to the engine (see maps.cpp)
1002 return (combo_class_buf[combobuf[combo].type].ladder_pass);
1003 }
1004
1005 // Returns the letter of the warp combo.
1006 int32_t zmap::warpindex(int32_t combo)
1007 {
1008 switch(combobuf[combo].type)
1009 {
1010 case cCAVE:
1011 case cPIT:
1012 case cSTAIR:
1013 case cCAVE2:
1014 case cSWIMWARP:
1015 case cDIVEWARP:
1016 case cSWARPA:
1017 return 0;
1018
1019 case cCAVEB:
1020 case cPITB:
1021 case cSTAIRB:
1022 case cCAVE2B:
1023 case cSWIMWARPB:
1024 case cDIVEWARPB:
1025 case cSWARPB:
1026 return 1;
1027
1028 case cCAVEC:
1029 case cPITC:
1030 case cSTAIRC:
1031 case cCAVE2C:
1032 case cSWIMWARPC:
1033 case cDIVEWARPC:
1034 case cSWARPC:
1035 return 2;
1036
1037 case cCAVED:
1038 case cPITD:
1039 case cSTAIRD:
1040 case cCAVE2D:
1041 case cSWIMWARPD:
1042 case cDIVEWARPD:
1043 case cSWARPD:
1044 return 3;
1045
1046 case cPITR:
1047 case cSTAIRR:
1048 case cSWARPR:
1049 return 4;
1050 }
1051
1052 return -1;
1053
1054 }
1055
1056 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
1057 {
1058 if(top)
1059 line(dest,x,y,x+15,y,c);
1060 rectfill(dest,x,y,x+3,y+15,c);
1061 rectfill(dest,x+12,y,x+15,y+15,c);
1062 rectfill(dest,x+4,y+2,x+11,y+5,c);
1063 rectfill(dest,x+4,y+10,x+11,y+13,c);
1064 }
1065
1066 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
1067 {
1068 line(dest,x,y,x+15,y,c);
1069 }
1070
1071 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
1072 {
1073 int32_t cx = COMBOX(pos);
1074 int32_t cy = COMBOY(pos);
1075
1076 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
1077
1078 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1079
1080 int32_t bridgedetected = 0;
1081
1082 for(int32_t i=0; i<4; i++)
1083 {
1084 int32_t tx=((i&2)<<2)+x;
1085 int32_t ty=((i&1)<<3)+y;
1086 int32_t tx2=((i&2)<<2)+cx;
1087 int32_t ty2=((i&1)<<3)+cy;
1088 for (int32_t m = layer; m <= 1; m++)
1089 {
1090 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1091 {
1092 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1093 {
1094 bridgedetected |= (1<<i);
1095 }
1096 }
1097 else
1098 {
1099 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1100 {
1101 bridgedetected |= (1<<i);
1102 }
1103 }
1104 }
1105 if (bridgedetected & (1<<i))
1106 {
1107 if (i >= 3) break;
1108 else continue;
1109 }
1110 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1111 {
1112 for(int32_t k=0; k<8; k+=2)
1113 for(int32_t j=0; j<8; j+=2)
1114 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1115 }
1116 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1117 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1118
1119 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1120 {
1121 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1122 {
1123 for(int32_t k=0; k<8; k+=2)
1124 for(int32_t j=0; j<8; j+=2)
1125 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1126 }
1127 else
1128 {
1129 int32_t color = COLOR_SOLID;
1130
1131 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1132 color=vc(6);
1133 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1134 color=vc(7);
1135
1136 rectfill(dest,tx,ty,tx+7,ty+7,color);
1137 }
1138 }
1139 }
1140
1141 bridgedetected = 0;
1142 for(int32_t i=0; i<4; i++)
1143 {
1144 int32_t tx2=((i&2)<<2)+cx;
1145 int32_t ty2=((i&1)<<3)+cy;
1146 for (int32_t m = 0; m <= 1; m++)
1147 {
1148 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1149 {
1150 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1151 {
1152 bridgedetected |= (1<<i);
1153 }
1154 }
1155 else
1156 {
1157 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1158 {
1159 bridgedetected |= (1<<i);
1160 }
1161 }
1162 }
1163 }
1164
1165 // Draw damage combos
1166 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1167 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1168 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1169 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1170 || combo_class_buf[c1.type].modify_hp_amount
1171 || combo_class_buf[c2.type].modify_hp_amount;
1172
1173 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1174
1175 if(dmg)
1176 {
1177 if (bridgedetected <= 0)
1178 {
1179 for(int32_t k=0; k<16; k+=2)
1180 for(int32_t j=0; j<16; j+=2)
1181 if(((k+j)/2)%2)
1182 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1183 }
1184 else
1185 {
1186 for(int32_t i=0; i<4; i++)
1187 {
1188 if (!(bridgedetected & (1<<i)))
1189 {
1190 int32_t tx=((i&2)<<2)+x;
1191 int32_t ty=((i&1)<<3)+y;
1192 for(int32_t k=0; k<8; k+=2)
1193 for(int32_t j=0; j<8; j+=2)
1194 if(((k+j)/2)%2)
1195 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1196 }
1197 }
1198 }
1199 }
1200
1201 if(c.type == cSLOPE)
1202 {
1203 slope_info s(c, x, y);
1204 s.draw(dest, 0, 0, COLOR_SLOPE);
1205 }
1206 auto fl0 = MAPFLAG2(-1,cx,cy);
1207 auto fl1 = MAPFLAG2(0,cx,cy);
1208 auto fl2 = MAPFLAG2(1,cx,cy);
1209 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1210 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1211 {
1212 bool top = false;
1213 if(cy)
1214 {
1215 top = true;
1216 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1217 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1218 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1219 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1220 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1221 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1222 {
1223 top = false;
1224 }
1225 }
1226 draw_ladder(dest,x,y,COLOR_LADDER,top);
1227 }
1228 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1229 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1230 {
1231 draw_platform(dest,x,y,COLOR_LADDER);
1232 }
1233 }
1234
1235 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1236 {
1237 int32_t cx = COMBOX(pos);
1238 int32_t cy = COMBOY(pos);
1239
1240 if (screen < 0) return;
1241 if (map < 0) return;
1242
1243 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1244
1245 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1246
1247 int32_t bridgedetected = 0;
1248 for(int32_t i=0; i<4; i++)
1249 {
1250 int32_t tx=((i&2)<<2)+x;
1251 int32_t ty=((i&1)<<3)+y;
1252 int32_t tx2=((i&2)<<2)+cx;
1253 int32_t ty2=((i&1)<<3)+cy;
1254 for (int32_t m = layer; m <= 1; m++)
1255 {
1256 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1257 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1258 {
1259 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1260 {
1261 bridgedetected |= (1<<i);
1262 }
1263 }
1264 else
1265 {
1266 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1267 {
1268 bridgedetected |= (1<<i);
1269 }
1270 }
1271 }
1272 if (bridgedetected & (1<<i))
1273 {
1274 continue;
1275 }
1276 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1277 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1278
1279
1280 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1281 {
1282 for(int32_t k=0; k<8; k+=2)
1283 for(int32_t j=0; j<8; j+=2)
1284 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1285 }
1286 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1287 {
1288 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1289 {
1290 for(int32_t k=0; k<8; k+=2)
1291 for(int32_t j=0; j<8; j+=2)
1292 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1293 }
1294 else
1295 {
1296 int32_t color = COLOR_SOLID;
1297
1298 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1299 color=vc(6);
1300 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1301 color=vc(7);
1302
1303 rectfill(dest,tx,ty,tx+7,ty+7,color);
1304 }
1305 }
1306 }
1307
1308 bridgedetected = 0;
1309 for(int32_t i=0; i<4; i++)
1310 {
1311 int32_t tx2=((i&2)<<2)+cx;
1312 int32_t ty2=((i&1)<<3)+cy;
1313 for (int32_t m = 0; m <= 1; m++)
1314 {
1315 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1316 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1317 {
1318 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1319 {
1320 bridgedetected |= (1<<i);
1321 }
1322 }
1323 else
1324 {
1325 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1326 {
1327 bridgedetected |= (1<<i);
1328 }
1329 }
1330 }
1331 }
1332
1333 // Draw damage combos
1334 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1335 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1336 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1337 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1338 || combo_class_buf[c1.type].modify_hp_amount
1339 || combo_class_buf[c2.type].modify_hp_amount;
1340
1341 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1342
1343 if(dmg)
1344 {
1345 if (bridgedetected <= 0)
1346 {
1347 for(int32_t k=0; k<16; k+=2)
1348 for(int32_t j=0; j<16; j+=2)
1349 if(((k+j)/2)%2)
1350 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1351 }
1352 else
1353 {
1354 for(int32_t i=0; i<4; i++)
1355 {
1356 if (!(bridgedetected & (1<<i)))
1357 {
1358 int32_t tx=((i&2)<<2)+x;
1359 int32_t ty=((i&1)<<3)+y;
1360 for(int32_t k=0; k<8; k+=2)
1361 for(int32_t j=0; j<8; j+=2)
1362 if(((k+j)/2)%2)
1363 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1364 }
1365 }
1366 }
1367 }
1368
1369 if(c.type == cSLOPE)
1370 {
1371 slope_info s(c, x, y);
1372 s.draw(dest, 0, 0, COLOR_SLOPE);
1373 }
1374 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1375 auto fl1 = MAPFLAG3(map,screen,0,pos);
1376 auto fl2 = MAPFLAG3(map,screen,1,pos);
1377 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1378 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1379 {
1380 bool top = false;
1381 if(cy)
1382 {
1383 top = true;
1384 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1385 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1386 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1387 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1388 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1389 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1390 {
1391 top = false;
1392 }
1393 }
1394 draw_ladder(dest,x,y,COLOR_LADDER,top);
1395 }
1396 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1397 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1398 {
1399 draw_platform(dest,x,y,COLOR_LADDER);
1400 }
1401 }
1402
1403 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1404 {
1405 const newcombo& c = combobuf[cmbdat];
1406
1407 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1408
1409 for(int32_t i=0; i<4; i++)
1410 {
1411 int32_t tx=((i&2)<<2)+x;
1412 int32_t ty=((i&1)<<3)+y;
1413
1414 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1415 {
1416 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1417 {
1418 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1419 }
1420 else
1421 {
1422 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1423 }
1424 }
1425
1426
1427 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1428 {
1429 for(int32_t k=0; k<8; k+=2)
1430 for(int32_t j=0; j<8; j+=2)
1431 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1432 }
1433 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1434 {
1435 if(c.type==cLADDERHOOKSHOT)
1436 {
1437 for(int32_t k=0; k<8; k+=2)
1438 for(int32_t j=0; j<8; j+=2)
1439 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1440 }
1441 else
1442 {
1443 int32_t color = COLOR_SOLID;
1444
1445 if(c.type==cLADDERONLY)
1446 color=vc(6);
1447 else if(c.type==cHOOKSHOTONLY)
1448 color=vc(7);
1449
1450 rectfill(dest,tx,ty,tx+7,ty+7,color);
1451 }
1452 }
1453
1454 // Draw damage combos
1455 if(combo_class_buf[c.type].modify_hp_amount != 0)
1456 {
1457 for(int32_t k=0; k<8; k+=2)
1458 for(int32_t j=0; j<8; j+=2)
1459 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1460 }
1461 }
1462
1463 if(c.type == cSLOPE)
1464 {
1465 slope_info s(c, 0, 0);
1466 zfix const& slope = s.slope();
1467
1468 BITMAP* sub = create_bitmap_ex(8,16,16);
1469 clear_bitmap(sub);
1470 s.draw(sub, 0, 0, COLOR_SLOPE);
1471 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1472 destroy_bitmap(sub);
1473 }
1474 if(c.flag == mfSIDEVIEWLADDER)
1475 {
1476 draw_ladder(dest,x,y,COLOR_LADDER);
1477 }
1478 else if(c.flag == mfSIDEVIEWPLATFORM)
1479 {
1480 draw_platform(dest,x,y,COLOR_LADDER);
1481 }
1482 }
1483
1484 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1485 {
1486 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1487 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1488 }
1489 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1490 {
1491 newcombo const& c = combobuf[cmbdat];
1492
1493 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1494 {
1495 if(sflag)
1496 {
1497 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1498 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1499 }
1500
1501 if(c.flag)
1502 {
1503 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1504 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1505 }
1506 }
1507
1508 if(flags&cCSET)
1509 {
1510 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1511 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1512 }
1513 else if(flags&cCTYPE)
1514 {
1515 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1516 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1517 }
1518 }
1519
1520 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1521 {
1522 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1523
1524 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1525 if(repos)
1526 {
1527 combotile_override_x = x+(8*(scale-1));
1528 combotile_override_y = y+(8*(scale-1));
1529 }
1530 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1531 if(repos) combotile_override_x = combotile_override_y = -1;
1532 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1533 destroy_bitmap(b);
1534 }
1535 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1536 {
1537 static newcombo nilcombo;
1538 nilcombo.tile = 0;
1539
1540 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1541
1542 if(c.tile==0)
1543 {
1544 rectfill(dest,x,y,x+15,y+15,vc(0));
1545 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1546 return;
1547 }
1548
1549 putcombo(dest,x,y,cmbdat,cset);
1550
1551 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1552 {
1553 if(sflag)
1554 {
1555 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1556 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1557 }
1558
1559 if(combobuf[cmbdat].flag)
1560 {
1561 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1562 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1563 }
1564 }
1565
1566 if(flags&cWALK)
1567 {
1568 put_walkflags(dest,x,y,cmbdat,0);
1569 }
1570
1571 if(flags&cCSET)
1572 {
1573 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1574 // text_mode(inv?vc(15):vc(0));
1575 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1576 }
1577 else if(flags&cCTYPE)
1578 {
1579 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1580 // text_mode(inv?vc(15):vc(0));
1581 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1582 }
1583 }
1584 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1585 {
1586 auto blitx = 1 + (slot % 16) * 17;
1587 auto blity = 1 + (slot / 16) * 17;
1588 masked_stretch_blit(asset_engravings_bmp, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1589 }
1590
1591
1592 void copy_mapscr(mapscr *dest, const mapscr *src)
1593 {
1594 if(!dest || !src) return;
1595 *dest = *src;
1596 }
1597
1598 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1599 {
1600 int32_t x=0,y=0;
1601 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1602
1603 switch(side)
1604 {
1605 case up:
1606 case down:
1607 x=((pos&15)<<4)+xofs;
1608 y=(ignorepos?0:(pos&0xF0))+yofs;
1609 break;
1610
1611 case left:
1612 case right:
1613 x=(ignorepos?0:((pos&15)<<4))+xofs;
1614 y=(pos&0xF0)+yofs;
1615 break;
1616 }
1617
1618 switch(type)
1619 {
1620 case dt_lock:
1621 case dt_shut:
1622 case dt_boss:
1623 case dt_bomb:
1624 switch(side)
1625 {
1626 case up:
1627 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1628 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1629 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1630 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1631 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1632 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1633 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1634 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1635 break;
1636
1637 case down:
1638 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1639 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1640 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1641 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1642 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1643 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1644 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1645 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1646 break;
1647
1648 case left:
1649 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1650 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1651 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1652 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1653 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1654 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1655
1656 if(x+16 >= dest->w)
1657 break;
1658
1659 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1660 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1661 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1662 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1663 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1664 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1665 break;
1666
1667 case right:
1668
1669 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1670 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1671 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1672 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1673 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1674 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1675
1676 if(x+16 <= 0)
1677 break;
1678
1679 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1680 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1681 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1682 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1683 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1684 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1685 break;
1686 }
1687
1688 break;
1689
1690 case dt_pass:
1691 case dt_wall:
1692 case dt_walk:
1693 default:
1694 break;
1695 }
1696 }
1697
1698 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1699 {
1700 int32_t x=((pos&15)<<4)+xofs;
1701 int32_t y=(pos&0xF0)+yofs;
1702 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1703
1704
1705 switch(side)
1706 {
1707 case up:
1708 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1709 {
1710 overcombo(dest,x,y,
1711 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1712 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1713 }
1714
1715 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1716 {
1717 overcombo(dest,x+16,y,
1718 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1719
1720 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1721 }
1722
1723 break;
1724
1725 case down:
1726 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1727 {
1728 overcombo(dest,x,y,
1729 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1730 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1731 }
1732
1733 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1734 {
1735 overcombo(dest,x+16,y,
1736 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1737 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1738 }
1739
1740 break;
1741
1742 case left:
1743 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1744 {
1745 overcombo(dest,x,y,
1746 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1747 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1748 }
1749
1750 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1751 {
1752 overcombo(dest,x,y+16,
1753 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1754 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1755 }
1756
1757 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1758 {
1759 overcombo(dest,x,y+32,
1760 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1761 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1762 }
1763
1764 break;
1765
1766 case right:
1767 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1768 {
1769 overcombo(dest,x,y,
1770 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1771 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1772 }
1773
1774 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1775 {
1776 overcombo(dest,x,y+16,
1777
1778 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1779 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1780 }
1781
1782 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1783 {
1784 overcombo(dest,x,y+32,
1785 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1786 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1787 }
1788
1789 break;
1790 }
1791 }
1792
1793 bool zmap::misaligned(int32_t map, int32_t screen, int32_t i, int32_t dir)
1794 {
1795 word cmbcheck1, cmbcheck2;
1796 newcombo combocheck1, combocheck2;
1797 combocheck1 = combobuf[0];
1798 combocheck2 = combobuf[0];
1799 combocheck1.walk = 0;
1800 combocheck2.walk = 0;
1801
1802 int32_t layermap, layerscreen;
1803
1804 switch(dir)
1805 {
1806 case up:
1807 {
1808 if(i>15) //not top row of combos
1809 {
1810 return false;
1811 }
1812
1813 if(screen<16) //top row of screens
1814 {
1815 return false;
1816
1817 }
1818
1819 //check main screen
1820 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1821 cmbcheck2 = vbound(AbsoluteScr(map, screen-16)->data[i+160], 0, MAXCOMBOS-1);
1822 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1823 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1824
1825 //check layer 1
1826 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1827
1828 if(layermap>-1 && layermap<map_count)
1829 {
1830 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1831 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1832 if (combobuf[cmbcheck1].type == cBRIDGE)
1833 {
1834 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1835 {
1836 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1837 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1838 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1839 }
1840 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1841 }
1842 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1843 }
1844
1845 layermap=AbsoluteScr(map, screen-16)->layermap[0]-1;
1846
1847 if(layermap>-1 && layermap<map_count)
1848 {
1849 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[0];
1850 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1851 if (combobuf[cmbcheck2].type == cBRIDGE)
1852 {
1853 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1854 {
1855 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1856 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1857 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1858 }
1859 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1860 }
1861 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1862 }
1863
1864 //check layer 2
1865 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1866
1867 if(layermap>-1 && layermap<map_count)
1868 {
1869 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1870
1871 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1872 if (combobuf[cmbcheck2].type == cBRIDGE)
1873 {
1874 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1875 {
1876 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1877 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1878 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1879 }
1880 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1881 }
1882 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1883 }
1884
1885 layermap=AbsoluteScr(map, screen-16)->layermap[1]-1;
1886
1887 if(layermap>-1 && layermap<map_count)
1888 {
1889 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[1];
1890 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1891 if (combobuf[cmbcheck2].type == cBRIDGE)
1892 {
1893 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1894 {
1895 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1896 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1897 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1898 }
1899 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1900 }
1901 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1902 }
1903
1904 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1905 {
1906 return true;
1907 }
1908
1909 break;
1910 }
1911 case down:
1912 {
1913 if(i<160) //not bottom row of combos
1914 {
1915 return false;
1916 }
1917
1918 if(screen>111) //bottom row of screens
1919 {
1920 return false;
1921 }
1922
1923 //check main screen
1924 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1925 cmbcheck2 = vbound(AbsoluteScr(map, screen+16)->data[i-160], 0, MAXCOMBOS-1);
1926 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1927 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1928
1929
1930 //check layer 1
1931 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1932
1933 if(layermap>-1 && layermap<map_count)
1934 {
1935 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1936 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1937 if (combobuf[cmbcheck1].type == cBRIDGE)
1938 {
1939 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1940 {
1941 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1942 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1943 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1944 }
1945 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1946 }
1947 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1948 }
1949
1950 layermap=AbsoluteScr(map, screen+16)->layermap[0]-1;
1951
1952 if(layermap>-1 && layermap<map_count)
1953 {
1954 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[0];
1955 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1956 if (combobuf[cmbcheck2].type == cBRIDGE)
1957 {
1958 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1959 {
1960 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1961 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1962 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1963 }
1964 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1965 }
1966 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1967 }
1968
1969 //check layer 2
1970 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1971
1972 if(layermap>-1 && layermap<map_count)
1973 {
1974 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1975 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1976 if (combobuf[cmbcheck1].type == cBRIDGE)
1977 {
1978 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1979 {
1980 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1981 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1982 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1983 }
1984 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1985 }
1986 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1987 }
1988
1989 layermap=AbsoluteScr(map, screen+16)->layermap[1]-1;
1990
1991 if(layermap>-1 && layermap<map_count)
1992 {
1993 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[1];
1994 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1995 if (combobuf[cmbcheck2].type == cBRIDGE)
1996 {
1997 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1998 {
1999 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2000 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2001 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2002 }
2003 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2004 }
2005 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2006 }
2007
2008 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
2009 {
2010 return true;
2011 }
2012
2013 break;
2014 }
2015 case left:
2016 {
2017 if((i&0xF)!=0) //not left column of combos
2018 {
2019 return false;
2020 }
2021
2022 if((screen&0xF)==0) //left column of screens
2023 {
2024 return false;
2025 }
2026
2027 //check main screen
2028 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2029 cmbcheck2 = AbsoluteScr(map, screen-1)->data[i+15];
2030 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2031 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2032
2033 //check layer 1
2034 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2035
2036 if(layermap>-1 && layermap<map_count)
2037 {
2038 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2039 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2040 if (combobuf[cmbcheck1].type == cBRIDGE)
2041 {
2042 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2043 {
2044 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2045 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2046 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2047 }
2048 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2049 }
2050 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2051 }
2052
2053 layermap=AbsoluteScr(map, screen-1)->layermap[0]-1;
2054
2055 if(layermap>-1 && layermap<map_count)
2056 {
2057 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[0];
2058 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2059 if (combobuf[cmbcheck2].type == cBRIDGE)
2060 {
2061 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2062 {
2063 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2064 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2065 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2066 }
2067 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2068 }
2069 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2070 }
2071
2072 //check layer 2
2073 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2074
2075 if(layermap>-1 && layermap<map_count)
2076 {
2077 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2078 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2079 if (combobuf[cmbcheck1].type == cBRIDGE)
2080 {
2081 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2082 {
2083 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2084 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2085 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2086 }
2087 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2088 }
2089 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2090 }
2091
2092 layermap=AbsoluteScr(map, screen-1)->layermap[1]-1;
2093
2094 if(layermap>-1 && layermap<map_count)
2095 {
2096 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[1];
2097 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2098 if (combobuf[cmbcheck2].type == cBRIDGE)
2099 {
2100 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2101 {
2102 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2103 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2104 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2105 }
2106 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2107 }
2108 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2109 }
2110
2111 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2112 {
2113 return true;
2114 }
2115
2116 break;
2117 }
2118 case right:
2119 {
2120 if((i&0xF)!=15) //not right column of combos
2121 {
2122 return false;
2123 }
2124
2125 if((screen&0xF)==15) //right column of screens
2126 {
2127 return false;
2128 }
2129
2130 //check main screen
2131 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2132 cmbcheck2 = AbsoluteScr(map, screen+1)->data[i-15];
2133 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2134 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2135
2136 //check layer 1
2137 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2138
2139 if(layermap>-1 && layermap<map_count)
2140 {
2141 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2142 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2143 if (combobuf[cmbcheck1].type == cBRIDGE)
2144 {
2145 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2146 {
2147 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2148 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2149 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2150 }
2151 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2152 }
2153 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2154 }
2155
2156 layermap=AbsoluteScr(map, screen+1)->layermap[0]-1;
2157
2158 if(layermap>-1 && layermap<map_count)
2159 {
2160 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[0];
2161 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2162 if (combobuf[cmbcheck2].type == cBRIDGE)
2163 {
2164 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2165 {
2166 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2167 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2168 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2169 }
2170 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2171 }
2172 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2173 }
2174
2175 //check layer 2
2176 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2177
2178 if(layermap>-1 && layermap<map_count)
2179 {
2180 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2181 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2182 if (combobuf[cmbcheck1].type == cBRIDGE)
2183 {
2184 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2185 {
2186 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2187 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2188 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2189 }
2190 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2191 }
2192 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2193 }
2194
2195 layermap=AbsoluteScr(map, screen+1)->layermap[1]-1;
2196
2197 if(layermap>-1 && layermap<map_count)
2198 {
2199 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[1];
2200
2201 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2202 if (combobuf[cmbcheck2].type == cBRIDGE)
2203 {
2204 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2205 {
2206 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2207 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2208 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2209 }
2210 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2211 }
2212 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2213 }
2214
2215 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2216 {
2217 return true;
2218 }
2219
2220 break;
2221 }
2222 }
2223
2224 return false;
2225 }
2226
2227 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2228 {
2229 int32_t checkcombo;
2230
2231 if(alignment_arrow_timer>31)
2232 {
2233 if(scr<0)
2234 {
2235 scr=cursor.screen;
2236 }
2237
2238 if((scr<128)) //do the misalignment arrows
2239 {
2240 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2241 {
2242 if(misaligned(cursor.map, scr, checkcombo, up))
2243 {
2244 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2245 }
2246 }
2247
2248 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2249 {
2250 if(misaligned(cursor.map, scr, checkcombo, down))
2251 {
2252 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2253 }
2254 }
2255
2256 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2257 {
2258 if(misaligned(cursor.map, scr, checkcombo, left))
2259 {
2260 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2261 }
2262 }
2263
2264 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2265 {
2266 if(misaligned(cursor.map, scr, checkcombo, right))
2267 {
2268 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2269 }
2270 }
2271
2272 int32_t tempalign;
2273
2274 //check top left corner
2275 checkcombo=0;
2276 tempalign=0;
2277 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2278 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2279
2280 switch(tempalign)
2281 {
2282 case 0:
2283 break;
2284
2285 case 1: //up
2286 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2287 break;
2288
2289 case 2: //left
2290 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2291 break;
2292
2293 case 3: //up-left
2294 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2295 break;
2296 }
2297
2298 //check top right corner
2299 checkcombo=15;
2300 tempalign=0;
2301 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2302 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2303
2304 switch(tempalign)
2305 {
2306 case 0:
2307 break;
2308
2309 case 1: //up
2310 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2311 break;
2312
2313 case 2: //right
2314 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2315 break;
2316
2317 case 3: //up-right
2318 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2319 break;
2320 }
2321
2322 //check bottom left corner
2323 checkcombo=160;
2324 tempalign=0;
2325 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2326 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2327
2328 switch(tempalign)
2329 {
2330 case 0:
2331 break;
2332
2333 case 1: //down
2334 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2335 break;
2336
2337 case 2: //left
2338 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2339 break;
2340
2341 case 3: //down-left
2342 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2343 break;
2344 }
2345
2346 //check bottom right corner
2347
2348 checkcombo=175;
2349 tempalign=0;
2350 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2351 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2352
2353 switch(tempalign)
2354 {
2355 case 0:
2356 break;
2357
2358 case 1: //down
2359 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2360 break;
2361
2362 case 2: //right
2363 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2364 break;
2365
2366 case 3: //down-right
2367 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2368 break;
2369 }
2370 }
2371 }
2372 }
2373
2374 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2375 {
2376 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2377 }
2378
2379 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2380 {
2381 if (map < 0 || screen < 0) return 0;
2382
2383 if(pos>175 || pos < 0)
2384 return 0;
2385
2386 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2387
2388 if (!m->is_valid()) return 0;
2389
2390 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2391
2392 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2393
2394 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2395
2396 if (!scr->is_valid()) return 0;
2397
2398 return scr->data[pos]; // entire combo code
2399 }
2400
2401 // Takes array index layer num., not actual layer num.
2402 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2403 {
2404 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2405
2406 if(map<0)
2407 map=cursor.map;
2408
2409 if(scr<0)
2410 scr=cursor.screen;
2411
2412 mapscr *screen1;
2413
2414 if(prv_mode)
2415 {
2416 screen1=get_prvscr();
2417 }
2418 else
2419 {
2420 screen1=AbsoluteScr(cursor.map,cursor.screen);
2421 }
2422
2423 int32_t layermap;
2424 layermap=screen1->layermap[lyr]-1;
2425
2426 if(layermap<0 || layermap >= map_count) return 0;
2427
2428 mapscr *layer;
2429
2430 if(prv_mode)
2431 layer = &prvlayers[lyr];
2432 else
2433 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2434
2435 int32_t pos = COMBOPOS(x,y);
2436
2437 if(pos>175 || pos < 0)
2438 return 0;
2439
2440 return layer->data[pos];
2441 }
2442
2443 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2444 {
2445 if(map<0)
2446 map=cursor.map;
2447
2448 if(scr<0)
2449 scr=cursor.screen;
2450
2451 mapscr *screen1;
2452
2453 if(prv_mode)
2454 {
2455 screen1=get_prvscr();
2456 }
2457 else
2458 {
2459 screen1=AbsoluteScr(cursor.map,cursor.screen);
2460 }
2461
2462 x = vbound(x, 0, 16*16);
2463 y = vbound(y, 0, 11*16);
2464 int32_t combo = COMBOPOS(x,y);
2465
2466 if(combo>175 || combo < 0)
2467 return 0;
2468
2469 return screen1->data[combo];
2470 }
2471
2472 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2473 {
2474 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2475 }
2476
2477 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2478 {
2479 if (map < 0 || screen < 0) return 0;
2480
2481 if(pos>175 || pos < 0)
2482 return 0;
2483
2484 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2485
2486 if (!m->is_valid()) return 0;
2487
2488 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2489
2490 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2491
2492 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2493
2494 if (!scr->is_valid()) return 0;
2495
2496 return scr->sflag[pos]; // entire combo code
2497 }
2498
2499 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2500 {
2501 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2502
2503 if(map<0)
2504 map=cursor.map;
2505
2506 if(scr<0)
2507 scr=cursor.screen;
2508
2509 mapscr *screen1;
2510
2511 if(prv_mode)
2512 {
2513 screen1=get_prvscr();
2514 }
2515 else
2516 {
2517 screen1=AbsoluteScr(cursor.map,cursor.screen);
2518 }
2519
2520 int32_t layermap;
2521 layermap=screen1->layermap[lyr]-1;
2522
2523 if(layermap<0 || layermap >= map_count) return 0;
2524
2525 mapscr *layer;
2526
2527 if(prv_mode)
2528 layer = &prvlayers[lyr];
2529 else
2530 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2531
2532 int32_t combo = COMBOPOS(x,y);
2533
2534 if(combo>175 || combo < 0)
2535 return 0;
2536
2537 return layer->sflag[combo];
2538 }
2539
2540 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2541 {
2542 if(map<0)
2543 map=cursor.map;
2544
2545 if(scr<0)
2546 scr=cursor.screen;
2547
2548 mapscr *screen1;
2549
2550 if(prv_mode)
2551 {
2552 screen1=get_prvscr();
2553 }
2554 else
2555 {
2556 screen1=AbsoluteScr(cursor.map,cursor.screen);
2557 }
2558
2559 x = vbound(x, 0, 16*16);
2560 y = vbound(y, 0, 11*16);
2561 int32_t combo = COMBOPOS(x,y);
2562
2563 if(combo>175 || combo < 0)
2564 return 0;
2565
2566 return screen1->sflag[combo];
2567 }
2568
2569 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2570 {
2571 mapscr *layers[7];
2572 mapscr *basescr;
2573 if(prv_mode)
2574 {
2575 layers[0] = &prvscr;
2576 basescr = layers[0];
2577 for(auto q = 1; q < 7; ++q)
2578 {
2579 if(prvlayers[q-1].valid)
2580 layers[q] = &(prvlayers[q-1]);
2581 else layers[q] = NULL;
2582 }
2583 }
2584 else
2585 {
2586 layers[0] = AbsoluteScr(cursor.map, cursor.screen);
2587 basescr = layers[0];
2588 for(auto q = 1; q < 7; ++q)
2589 {
2590 int32_t lmap = basescr->layermap[q-1]-1;
2591 int32_t lscr = basescr->layerscreen[q-1];
2592 if(lmap < 0)
2593 layers[q] = NULL;
2594 else layers[q] = AbsoluteScr(lmap, lscr);
2595 }
2596 }
2597 for(auto q = 0; q < 7; ++q)
2598 {
2599 if(!layers[q]) continue;
2600 for(auto pos = 0; pos < 176; ++pos)
2601 {
2602 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2603 if(cmb.type == cTORCH)
2604 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2605 }
2606 }
2607 word maxffc = basescr->numFFC();
2608 for(auto q = 0; q < maxffc; ++q)
2609 {
2610 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2611 if(cmb.type == cTORCH)
2612 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2613 }
2614 }
2615
2616 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2617 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2618 {
2619 newcombo const& cmb = combobuf[cid];
2620 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2621 if(dither)
2622 {
2623 if (LayerDitherSz == 0)
2624 return;
2625 BITMAP* buf = create_bitmap_ex(8,16,16);
2626 clear_bitmap(buf);
2627 overcombo(buf,0,0,cid,cset);
2628 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2629 if(over)
2630 {
2631 if(transp)
2632 {
2633 color_map = trans_table2;
2634 draw_trans_sprite(dest, buf, x, y);
2635 color_map = trans_table;
2636 }
2637 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2638 }
2639 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2640 destroy_bitmap(buf);
2641 }
2642 else if(over)
2643 {
2644 if(transp)
2645 overcombotranslucent(dest,x,y,cid,cset,0);
2646 else overcombo(dest,x,y,cid,cset);
2647 }
2648 else put_combo(dest,x,y,cid,cset,flags,sflag);
2649 }
2650 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2651 {
2652 if(!md) return;
2653
2654 // These should only be drawn for the currently selected layer, not every layer.
2655 SETFLAG(flags, cCSET, false);
2656 SETFLAG(flags, cCTYPE, false);
2657
2658 for (int32_t i = 0; i < 176; i++)
2659 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2660 }
2661 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2662 {
2663 if(!md) return;
2664
2665 // These should only be drawn for the currently selected layer, not every layer.
2666 SETFLAG(flags, cCSET, false);
2667 SETFLAG(flags, cCTYPE, false);
2668
2669 for (int32_t i = 0; i < 176; i++)
2670 {
2671 int data = md->data[i];
2672 if(combo_class_buf[combobuf[data].type].overhead)
2673 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2674 }
2675 }
2676 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2677 {
2678 if(!LayerMaskInt[lyr])
2679 return nullptr;
2680 if(lyr == 0)
2681 return basescr;
2682 int layermap = basescr->layermap[lyr-1]-1;
2683
2684 if(layermap>-1 && layermap<map_count)
2685 {
2686 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2687 return &TheMaps[layerscreen];
2688 }
2689 return nullptr;
2690 }
2691 static void _zmap_draw_ffc_layer(BITMAP* dest,int32_t x,int32_t y,int32_t flags,mapscr* basescr, int32_t layer)
2692 {
2693 int num_ffcs = basescr->numFFC();
2694 for(int32_t i=num_ffcs-1; i>=0; i--)
2695 {
2696 auto const& ff = basescr->ffcs[i];
2697 if(ff.data)
2698 {
2699 if(!(ff.flags&ffc_changer))
2700 {
2701 int32_t tx=(ff.x.getInt())+x;
2702 int32_t ty=(ff.y.getInt())+y;
2703
2704 if((ff.flags&ffc_overlay) ? layer == -1 : layer == ff.layer)
2705 {
2706 if(ff.flags&ffc_trans)
2707 overcomboblocktranslucent(dest,tx,ty,ff.data, ff.cset, ff.txsz, ff.tysz,128);
2708 else
2709 overcomboblock(dest, tx, ty, ff.data, ff.cset, ff.txsz, ff.tysz);
2710 }
2711 }
2712 }
2713 }
2714 }
2715 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t screen,int32_t hl_layer)
2716 {
2717 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2718 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2719 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
2720
2721 if(map<0)
2722 map=cursor.map;
2723
2724 if(screen<0)
2725 screen=cursor.screen;
2726
2727 mapscr *basescr;
2728 mapscr* layers[7] = {nullptr};
2729
2730 if(prv_mode)
2731 {
2732 hl_layer = -1;
2733 basescr=get_prvscr();
2734 }
2735 else
2736 {
2737 basescr=AbsoluteScr(map,screen);
2738 }
2739 layers[0] = _zmap_get_lyr_checked(0,basescr);
2740 for(int lyr = 1; lyr < 7; ++lyr)
2741 {
2742 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2743 : _zmap_get_lyr_checked(lyr,basescr);
2744 }
2745
2746 if(!(basescr->valid&mVALID))
2747 {
2748 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2749 rectfill(dest,x,y,x+255,y+175,vc(1));
2750
2751 if(ShowMisalignments)
2752 {
2753 check_alignments(dest,x,y,screen);
2754 }
2755
2756 return;
2757 }
2758
2759 if(LayerMaskInt[0]==0 || !get_qr(qr_CLASSIC_DRAWING_ORDER))
2760 {
2761 byte bgfill = 0;
2762 if (LayerDitherBG > -1)
2763 bgfill = vc(LayerDitherBG);
2764 rectfill(dest,x,y,x+255,y+175,bgfill);
2765 }
2766
2767 if(olddraw)
2768 {
2769 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2770 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2771 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2772 }
2773 else for (int lyr = -7; lyr < -3; ++lyr)
2774 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, lyr);
2775
2776 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2777 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2778 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -3);
2779
2780 if(!olddraw)
2781 {
2782 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2783 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, true, HL_LAYER(2));
2784 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2785 }
2786 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -1);
2787
2788 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, !olddraw || (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2789 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 0);
2790
2791
2792 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2793 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 1);
2794
2795 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2796 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2797 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 2);
2798
2799 struct DoorDrawData
2800 {
2801 int over_pos; // Position for over_door (dBOMB)
2802 int put_pos; // Position for put_door (standard doors)
2803 int walk_x; // Pre-calculated X offset for dWALK
2804 int walk_y; // Pre-calculated Y offset for dWALK
2805 };
2806
2807 static const DoorDrawData door_data[4] = {
2808 // over, put, walk_x, walk_y
2809 { 39, 7, 120, 16 }, // up
2810 { 135, 151, 120, 144 }, // down
2811 { 66, 64, 16, 80 }, // left
2812 { 77, 78, 224, 80 } // right
2813 };
2814
2815 auto door_set = DoorComboSets[screens[cursor.screen].door_combo_set];
2816 bool walk_trans = get_bit(door_set.flags, df_walktrans);
2817
2818 int32_t doortype[4];
2819 for(int32_t i=0; i<4; i++)
2820 {
2821 switch(basescr->door[i])
2822 {
2823 case dOPEN: doortype[i]=dt_pass; break;
2824 case dLOCKED: doortype[i]=dt_lock; break;
2825 case d1WAYSHUTTER:
2826 case dSHUTTER: doortype[i]=dt_shut; break;
2827 case dBOSS: doortype[i]=dt_boss; break;
2828 case dBOMB: doortype[i]=dt_bomb; break;
2829 default: doortype[i]=0; // Default or unhandled
2830 }
2831 }
2832
2833 for (int i = 0; i < 4; ++i)
2834 {
2835 const auto& d = door_data[i];
2836 const int current_door_type_id = basescr->door[i];
2837
2838 switch (current_door_type_id) {
2839 case dBOMB:
2840 // Draw bombable overlay, then fall through to draw the door
2841 over_door(dest, d.over_pos, i, x, y, false, screen);
2842 [[fallthrough]];
2843
2844 case dOPEN:
2845 case dLOCKED:
2846 case d1WAYSHUTTER:
2847 case dSHUTTER:
2848 case dBOSS:
2849 {
2850 put_door(dest, d.put_pos, i, doortype[i], x, y, false, screen);
2851 break;
2852 }
2853
2854 case dWALK:
2855 if (walk_trans) {
2856 overcombo(dest, d.walk_x + x, d.walk_y + y,
2857 door_set.walkthroughcombo[i],
2858 door_set.walkthroughcset[i]);
2859 } else {
2860 put_combo(dest, d.walk_x + x, d.walk_y + y,
2861 door_set.walkthroughcombo[i],
2862 door_set.walkthroughcset[i], 0, 0);
2863 }
2864 break;
2865 }
2866 }
2867
2868 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2869 {
2870 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2871 }
2872
2873 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2874 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2875 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 3);
2876
2877 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2878 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 4);
2879
2880 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2881
2882 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2883 {
2884 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2885 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2886 }
2887 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2888 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 5);
2889
2890 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -1);
2891
2892 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2893 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 6);
2894 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 7);
2895
2896 int num_ffcs = basescr->numFFC();
2897 for(int32_t i=num_ffcs-1; i>=0; i--) // changer ffcs
2898 if(basescr->ffcs[i].data)
2899 if(basescr->ffcs[i].flags&ffc_changer)
2900 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2901
2902 if(flags&cWALK)
2903 {
2904 if(layers[0])
2905 for(int32_t i=0; i<176; i++)
2906 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2907
2908 for(int32_t k=0; k<2; k++)
2909 {
2910 if(layers[k+1])
2911 for(int32_t i=0; i<176; i++)
2912 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2913 }
2914 for(int32_t i=num_ffcs-1; i>=0; i--)
2915 {
2916 if(auto data = basescr->ffcs[i].data)
2917 {
2918 if(!(basescr->ffcs[i].flags&ffc_changer))
2919 {
2920 newcombo const& cmb = combobuf[data];
2921 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2922 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2923
2924 if(basescr->ffcs[i].flags&ffc_solid)
2925 {
2926 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
2927 }
2928
2929 if(cmb.type == cSLOPE)
2930 {
2931 slope_info s(cmb, tx, ty);
2932 s.draw(dest, 0, 0, COLOR_SLOPE);
2933 }
2934 }
2935 }
2936 }
2937 }
2938
2939 if(flags&(cFLAGS|cCSET|cCTYPE))
2940 {
2941 if(LayerMaskInt[CurrentLayer]!=0)
2942 {
2943 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
2944 auto* scr = _lscr>-1 && _lscr<map_count*MAPSCRS ? &TheMaps[_lscr] : nullptr;
2945
2946 for(int32_t i=0; i<176; i++)
2947 {
2948 if(CurrentLayer==0)
2949 {
2950 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
2951 }
2952 else
2953 {
2954 if(prv_mode)
2955 {
2956 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
2957 }
2958 else if(basescr->layermap[CurrentLayer-1] > 0)
2959 {
2960 if(scr)
2961 {
2962 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
2963 scr->data[i],
2964 scr->cset[i], flags,
2965 scr->sflag[i]);
2966 }
2967 }
2968 }
2969 }
2970 }
2971 }
2972
2973 int32_t dark = basescr->flags&cDARK;
2974
2975 if(dark && !(flags&cNODARK)
2976 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
2977 {
2978 int col = vc(blackout_color);
2979 for(int32_t j=0; j<80; j++) {
2980 // Logic: ((i^j)&1)==0 means parity matches
2981 int start = (j&1);
2982 for(int32_t i=start; i<(80)-j; i+=2) {
2983 putpixel(dest,x+i,y+j,col);
2984 }
2985 }
2986 }
2987
2988 if(ShowMisalignments)
2989 {
2990 check_alignments(dest,x,y,screen);
2991 }
2992 }
2993
2994 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
2995 {
2996 if(map<0)
2997 map=cursor.map;
2998
2999 if(scr<0)
3000 scr=cursor.screen;
3001
3002 mapscr* layer=AbsoluteScr(map,scr);
3003 int32_t layermap=0, layerscreen=0;
3004
3005 if(!(layer->valid&mVALID))
3006 {
3007 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3008 rectfill(dest,x,y,x+255,y+15,vc(1));
3009 return;
3010 }
3011
3012 int32_t dark = layer->flags&4;
3013
3014 if(LayerMaskInt[0]==0)
3015 {
3016 rectfill(dest,x,y,x+255,y+15,0);
3017 }
3018
3019 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3020 int order[2] = {2,1};
3021 if (olddraw) zc_swap(order[0],order[1]);
3022 for(int k : order)
3023 {
3024 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3025 {
3026 layermap=layer->layermap[k]-1;
3027
3028 if(layermap>-1 && layermap<map_count)
3029 {
3030 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3031
3032 for(int32_t i=c; i<(c&0xF0)+16; i++)
3033 {
3034 auto data = TheMaps[layerscreen].data[i];
3035 auto cs = TheMaps[layerscreen].cset[i];
3036 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3037 }
3038 }
3039 }
3040 }
3041
3042 if(LayerMaskInt[0]!=0)
3043 {
3044 for(int32_t i=c; i<(c&0xF0)+16; i++)
3045 {
3046 word cmbdat = (i < 176 ? layer->data[i] : 0);
3047 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3048 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3049 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3050 cmbflag,!olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3051 }
3052 }
3053
3054 for(int32_t k=0; k<2; k++)
3055 {
3056 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3057 {
3058 layermap=layer->layermap[k]-1;
3059
3060 if(layermap>-1 && layermap<map_count)
3061 {
3062 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3063
3064 for(int32_t i=c; i<(c&0xF0)+16; i++)
3065 {
3066 auto data = TheMaps[layerscreen].data[i];
3067 auto cs = TheMaps[layerscreen].cset[i];
3068 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3069 }
3070 }
3071 }
3072 }
3073
3074 int32_t doortype[4];
3075
3076 for(int32_t i=0; i<4; i++)
3077 {
3078 switch(layer->door[i])
3079 {
3080 case dOPEN:
3081 doortype[i]=dt_pass;
3082 break;
3083
3084 case dLOCKED:
3085 doortype[i]=dt_lock;
3086 break;
3087
3088 case d1WAYSHUTTER:
3089 case dSHUTTER:
3090 doortype[i]=dt_shut;
3091 break;
3092
3093 case dBOSS:
3094 doortype[i]=dt_boss;
3095 break;
3096
3097 case dBOMB:
3098 doortype[i]=dt_bomb;
3099 break;
3100 }
3101 }
3102
3103 if(c<16)
3104 {
3105 switch(layer->door[up])
3106 {
3107 case dBOMB:
3108 case dOPEN:
3109 case dLOCKED:
3110 case d1WAYSHUTTER:
3111 case dSHUTTER:
3112 case dBOSS:
3113 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3114 break;
3115 }
3116 }
3117 else if(c>159)
3118 {
3119 switch(layer->door[down])
3120 {
3121 case dBOMB:
3122 case dOPEN:
3123 case dLOCKED:
3124 case d1WAYSHUTTER:
3125 case dSHUTTER:
3126 case dBOSS:
3127 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3128 break;
3129 }
3130 }
3131
3132 for(int32_t k=2; k<4; k++)
3133 {
3134 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3135 {
3136 layermap=layer->layermap[k]-1;
3137
3138 if(layermap>-1 && layermap<map_count)
3139 {
3140 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3141
3142 for(int32_t i=c; i<(c&0xF0)+16; i++)
3143 {
3144 if(layer->layeropacity[k]<255)
3145 {
3146 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3147 }
3148 else
3149 {
3150 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3151 }
3152 }
3153 }
3154 }
3155 }
3156
3157 //Overhead L0
3158 if(LayerMaskInt[0]!=0)
3159 {
3160 for(int32_t i=c; i<(c&0xF0)+16; i++)
3161 {
3162 int32_t ct1=layer->data[i];
3163 int32_t ct3=combobuf[ct1].type;
3164
3165 if(combo_class_buf[ct3].overhead)
3166 {
3167 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3168 }
3169 }
3170 }
3171
3172 //Overhead L1/2
3173 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3174 {
3175 for(int32_t k = 0; k < 2; ++k)
3176 {
3177 if(LayerMaskInt[k+1]!=0)
3178 {
3179 layermap=layer->layermap[k]-1;
3180
3181 if(layermap>-1 && layermap<map_count)
3182 {
3183 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3184 for(int32_t i=c; i<(c&0xF0)+16; i++)
3185 {
3186 auto data = TheMaps[layerscreen].data[i];
3187 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3188 auto cs = TheMaps[layerscreen].cset[i];
3189 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3190 }
3191 }
3192 }
3193 }
3194 }
3195
3196 for(int32_t k=4; k<6; k++)
3197 {
3198 if(LayerMaskInt[k+1]!=0)
3199 {
3200 layermap=layer->layermap[k]-1;
3201
3202 if(layermap>-1 && layermap<map_count)
3203 {
3204 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3205
3206 for(int32_t i=c; i<(c&0xF0)+16; i++)
3207 {
3208 auto data = TheMaps[layerscreen].data[i];
3209 auto cs = TheMaps[layerscreen].cset[i];
3210 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3211 }
3212 }
3213 }
3214 }
3215
3216 if(flags&cWALK)
3217 {
3218 if(LayerMaskInt[0]!=0)
3219 {
3220 for(int32_t i=c; i<(c&0xF0)+16; i++)
3221 {
3222 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3223 }
3224 }
3225
3226 for(int32_t k=0; k<2; k++)
3227 {
3228 if(LayerMaskInt[k+1]!=0)
3229 {
3230 for(int32_t i=c; i<(c&0xF0)+16; i++)
3231 {
3232 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3233 }
3234 }
3235 }
3236 }
3237
3238 if(flags&(cFLAGS|cCSET|cCTYPE))
3239 {
3240 if(LayerMaskInt[CurrentLayer]!=0)
3241 {
3242 for(int32_t i=c; i<(c&0xF0)+16; i++)
3243 {
3244 if(CurrentLayer==0)
3245 {
3246 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3247 }
3248 else
3249 {
3250 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3251
3252 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3253 {
3254 if(i < 176)
3255 {
3256 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3257 TheMaps[_lscr].data[i],
3258 TheMaps[_lscr].cset[i], flags|dark,
3259 TheMaps[_lscr].sflag[i]);
3260 }
3261 else
3262 {
3263 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3264 }
3265 }
3266 }
3267 }
3268 }
3269
3270 /*
3271 if (LayerMaskInt[0]!=0) {
3272 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3273 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3274 }
3275 }
3276 */
3277 }
3278
3279 if(ShowMisalignments)
3280 {
3281 if(c<16)
3282 {
3283 check_alignments(dest,x,y,scr);
3284 }
3285 else if(c>159)
3286 {
3287 check_alignments(dest,x,y-160,scr);
3288 }
3289 }
3290 }
3291
3292 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3293 {
3294 if(map<0)
3295 map=cursor.map;
3296
3297 if(scr<0)
3298 scr=cursor.screen;
3299
3300 mapscr* layer=AbsoluteScr(map,scr);
3301 int32_t layermap=0, layerscreen=0;
3302
3303 if(!(layer->valid&mVALID))
3304 {
3305 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3306 rectfill(dest,x,y,x+15,y+175,vc(1));
3307 return;
3308 }
3309
3310 int32_t dark = layer->flags&4;
3311
3312 if(LayerMaskInt[0]==0)
3313 {
3314 rectfill(dest,x,y,x+15,y+175,0);
3315 }
3316
3317 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3318 int order[2] = {2,1};
3319 if (olddraw) zc_swap(order[0],order[1]);
3320 for(int k : order)
3321 {
3322 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3323 {
3324 layermap=layer->layermap[k]-1;
3325
3326 if(layermap>-1 && layermap<map_count)
3327 {
3328 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3329
3330 for(int32_t i=c; i<176; i+=16)
3331 {
3332 auto data = TheMaps[layerscreen].data[i];
3333 auto cs = TheMaps[layerscreen].cset[i];
3334 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3335 }
3336 }
3337 }
3338 }
3339
3340 if(LayerMaskInt[0]!=0)
3341 {
3342 for(int32_t i=c; i<176; i+=16)
3343 {
3344 word cmbdat = layer->data[i];
3345 byte cmbcset = layer->cset[i];
3346 int32_t cmbflag = layer->sflag[i];
3347 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3348 !olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3349 }
3350 }
3351
3352 for(int32_t k=0; k<2; k++)
3353 {
3354 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3355 {
3356 layermap=layer->layermap[k]-1;
3357
3358 if(layermap>-1 && layermap<map_count)
3359 {
3360 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3361
3362 for(int32_t i=c; i<176; i+=16)
3363 {
3364 auto data = TheMaps[layerscreen].data[i];
3365 auto cs = TheMaps[layerscreen].cset[i];
3366 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3367 }
3368 }
3369 }
3370 }
3371
3372 int32_t doortype[4];
3373
3374 for(int32_t i=0; i<4; i++)
3375 {
3376 switch(layer->door[i])
3377 {
3378 case dOPEN:
3379 doortype[i]=dt_pass;
3380 break;
3381
3382 case dLOCKED:
3383 doortype[i]=dt_lock;
3384 break;
3385
3386 case d1WAYSHUTTER:
3387 case dSHUTTER:
3388 doortype[i]=dt_shut;
3389 break;
3390
3391 case dBOSS:
3392 doortype[i]=dt_boss;
3393 break;
3394
3395 case dBOMB:
3396 doortype[i]=dt_bomb;
3397 break;
3398 }
3399 }
3400
3401 if((c&0x0F)==0)
3402 {
3403 switch(layer->door[left])
3404 {
3405
3406 case dBOMB:
3407 case dOPEN:
3408 case dLOCKED:
3409 case d1WAYSHUTTER:
3410 case dSHUTTER:
3411 case dBOSS:
3412 // put_door(dest,64,left,doortype[left],x+256,y,true);
3413 put_door(dest,64,left,doortype[left],x,y,true,scr);
3414 break;
3415 }
3416 }
3417 else if((c&0x0F)==15)
3418 {
3419 switch(layer->door[right])
3420 {
3421 case dBOMB:
3422 case dOPEN:
3423 case dLOCKED:
3424 case d1WAYSHUTTER:
3425 case dSHUTTER:
3426 case dBOSS:
3427 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3428 break;
3429 }
3430 }
3431
3432 for(int32_t k=2; k<4; k++)
3433 {
3434 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3435 {
3436 layermap=layer->layermap[k]-1;
3437
3438 if(layermap>-1 && layermap<map_count)
3439 {
3440 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3441
3442 for(int32_t i=c; i<176; i+=16)
3443 {
3444 auto data = TheMaps[layerscreen].data[i];
3445 auto cs = TheMaps[layerscreen].cset[i];
3446 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3447 }
3448 }
3449 }
3450 }
3451
3452 //Overhead L0
3453 if(LayerMaskInt[0]!=0)
3454 {
3455 for(int32_t i=c; i<176; i+=16)
3456 {
3457 auto data = TheMaps[layerscreen].data[i];
3458 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3459 auto cs = TheMaps[layerscreen].cset[i];
3460 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3461 }
3462 }
3463 //Overhead L1/2
3464 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3465 {
3466 for(int32_t k = 0; k < 2; ++k)
3467 {
3468 if(LayerMaskInt[k+1]!=0)
3469 {
3470 layermap=layer->layermap[k]-1;
3471
3472 if(layermap>-1 && layermap<map_count)
3473 {
3474 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3475 for(int32_t i=c; i<176; i+=16)
3476 {
3477 auto data = TheMaps[layerscreen].data[i];
3478 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3479 auto cs = TheMaps[layerscreen].cset[i];
3480 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3481 }
3482 }
3483 }
3484 }
3485 }
3486
3487
3488 for(int32_t k=4; k<6; k++)
3489 {
3490 if(LayerMaskInt[k+1]!=0)
3491 {
3492 layermap=layer->layermap[k]-1;
3493
3494 if(layermap>-1 && layermap<map_count)
3495 {
3496 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3497
3498 for(int32_t i=c; i<176; i+=16)
3499 {
3500 auto data = TheMaps[layerscreen].data[i];
3501 auto cs = TheMaps[layerscreen].cset[i];
3502 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3503 }
3504 }
3505 }
3506 }
3507
3508 if(flags&cWALK)
3509 {
3510 if(LayerMaskInt[0]!=0)
3511 {
3512 for(int32_t i=c&0xF; i<176; i+=16)
3513 {
3514 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3515 }
3516 }
3517
3518 for(int32_t k=0; k<2; k++)
3519 {
3520 if(LayerMaskInt[k+1]!=0)
3521 {
3522 for(int32_t i=c&0xF; i<176; i+=16)
3523 {
3524 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3525 }
3526 }
3527 }
3528 }
3529
3530 if(flags&(cFLAGS|cCSET|cCTYPE))
3531 {
3532 if(LayerMaskInt[CurrentLayer]!=0)
3533 {
3534 for(int32_t i=c; i<176; i+=16)
3535 {
3536 if(CurrentLayer==0)
3537 {
3538 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3539 }
3540 else
3541 {
3542 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3543
3544 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3545 {
3546 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3547 TheMaps[_lscr].data[i],
3548 TheMaps[_lscr].cset[i], flags|dark,
3549 TheMaps[_lscr].sflag[i]);
3550 }
3551 }
3552 }
3553 }
3554 }
3555
3556 if(ShowMisalignments)
3557 {
3558 if((c&0x0F)==0)
3559 {
3560 check_alignments(dest,x,y,scr);
3561 }
3562 else if((c&0x0F)==15)
3563 {
3564 check_alignments(dest,x-240,y,scr);
3565 }
3566 }
3567 }
3568
3569 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3570 {
3571 if(map<0)
3572 map=cursor.map;
3573
3574 if(scr<0)
3575 scr=cursor.screen;
3576
3577 mapscr* layer=AbsoluteScr(map,scr);
3578 int32_t layermap=0, layerscreen=0;
3579
3580 if(!(layer->valid&mVALID))
3581 {
3582 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3583 rectfill(dest,x,y,x+15,y+15,vc(1));
3584 return;
3585 }
3586
3587 int32_t dark = layer->flags&4;
3588
3589 if(LayerMaskInt[0]!=0)
3590 {
3591 rectfill(dest,x,y,x+15,y+15,0);
3592 }
3593
3594 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3595 int order[2] = {2,1};
3596 if (olddraw) zc_swap(order[0],order[1]);
3597 for(int k : order)
3598 {
3599 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3600 {
3601 layermap=layer->layermap[k]-1;
3602
3603 if(layermap>-1 && layermap<map_count)
3604 {
3605 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3606
3607 auto data = TheMaps[layerscreen].data[c];
3608 auto cs = TheMaps[layerscreen].cset[c];
3609 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3610 }
3611 }
3612 }
3613
3614 if(LayerMaskInt[0]!=0)
3615 {
3616 word cmbdat = layer->data[c];
3617 byte cmbcset = layer->cset[c];
3618 int32_t cmbflag = layer->sflag[c];
3619 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3620 !olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3621 }
3622
3623
3624 for(int32_t k=0; k<2; k++)
3625 {
3626 if(LayerMaskInt[k+1]!=0)
3627 {
3628 layermap=layer->layermap[k]-1;
3629
3630 if(layermap>-1 && layermap<map_count)
3631 {
3632 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3633
3634 auto data = TheMaps[layerscreen].data[c];
3635 auto cs = TheMaps[layerscreen].cset[c];
3636 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3637 }
3638 }
3639 }
3640
3641 for(int32_t k=2; k<4; k++)
3642 {
3643 if(LayerMaskInt[k+1]!=0)
3644 {
3645 layermap=layer->layermap[k]-1;
3646
3647 if(layermap>-1 && layermap<map_count)
3648 {
3649 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3650 auto data = TheMaps[layerscreen].data[c];
3651 auto cs = TheMaps[layerscreen].cset[c];
3652 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3653 }
3654 }
3655 }
3656
3657 //Overhead L0
3658 if(LayerMaskInt[0]!=0)
3659 {
3660 auto data = TheMaps[layerscreen].data[c];
3661 if(combo_class_buf[combobuf[data].type].overhead)
3662 {
3663 auto cs = TheMaps[layerscreen].cset[c];
3664 drawcombo(dest,x,y,data,cs,0,0);
3665 }
3666 }
3667 //Overhead L1/2
3668 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3669 {
3670 for(int32_t k = 0; k < 2; ++k)
3671 {
3672 if(LayerMaskInt[k+1]!=0)
3673 {
3674 layermap=layer->layermap[k]-1;
3675
3676 if(layermap>-1 && layermap<map_count)
3677 {
3678 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3679 auto data = TheMaps[layerscreen].data[c];
3680 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3681 auto cs = TheMaps[layerscreen].cset[c];
3682 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3683 }
3684 }
3685 }
3686 }
3687
3688
3689 for(int32_t k=4; k<6; k++)
3690 {
3691 if(LayerMaskInt[k+1]!=0)
3692 {
3693 layermap=layer->layermap[k]-1;
3694
3695 if(layermap>-1 && layermap<map_count)
3696 {
3697 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3698 auto data = TheMaps[layerscreen].data[c];
3699 auto cs = TheMaps[layerscreen].cset[c];
3700 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3701 }
3702 }
3703 }
3704
3705 if(flags&cWALK)
3706 {
3707 if(LayerMaskInt[0]!=0)
3708 {
3709 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3710 }
3711
3712 for(int32_t k=0; k<2; k++)
3713 {
3714 if(LayerMaskInt[k+1]!=0)
3715 {
3716 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3717 }
3718 }
3719 }
3720
3721 if(flags&(cFLAGS|cCSET|cCTYPE))
3722 {
3723 if(LayerMaskInt[CurrentLayer]!=0)
3724 {
3725 int32_t i = c;
3726 //for(int32_t i=c; i==c; i++)
3727 {
3728 if(CurrentLayer==0)
3729 {
3730 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3731 }
3732 else
3733 {
3734 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3735
3736 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3737 {
3738 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3739 TheMaps[_lscr].data[i],
3740 TheMaps[_lscr].cset[i], flags|dark,
3741 TheMaps[_lscr].sflag[i]);
3742 }
3743 }
3744 }
3745 }
3746 }
3747
3748 if(ShowMisalignments)
3749 {
3750 switch(c)
3751 {
3752 case 0:
3753 check_alignments(dest,x,y,scr);
3754 break;
3755
3756 case 15:
3757 check_alignments(dest,x-240,y,scr);
3758 break;
3759
3760 case 160:
3761 check_alignments(dest,x,y-160,scr);
3762 break;
3763
3764 case 175:
3765 check_alignments(dest,x-240,y-160,scr);
3766 break;
3767 }
3768 }
3769 }
3770
3771 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3772 {
3773 if (InvalidBG == 2)
3774 {
3775 draw_checkerboard(dest, x, y, 16);
3776 }
3777 else if(InvalidBG == 1)
3778 {
3779 draw_static(dest, x, y, 16, 16);
3780 }
3781 else
3782 {
3783 rectfill(dest, x, y, x+15, y+15, vc(0));
3784 rect(dest, x, y, x+15, y+15, vc(15));
3785 line(dest, x, y, x+15, y+15, vc(15));
3786 line(dest, x, y+15, x+15, y, vc(15));
3787 }
3788 }
3789
3790 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3791 {
3792 if (InvalidBG == 2)
3793 {
3794 for(int32_t q = 0; q < 11; ++q)
3795 draw_checkerboard(dest, x, y + q * 16, 16);
3796 }
3797 else if(InvalidBG == 1)
3798 {
3799 draw_static(dest, x, y, 16, 176);
3800 }
3801 else
3802 {
3803 rectfill(dest, x, y, x+15, y+175, vc(0));
3804 rect(dest, x, y, x+15, y+175, vc(15));
3805 line(dest, x, y, x+15, y+175, vc(15));
3806 line(dest, x, y+175, x+15, y, vc(15));
3807 }
3808 }
3809
3810 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3811 {
3812 if (InvalidBG == 2)
3813 {
3814 for (int32_t q = 0; q < 16; ++q)
3815 draw_checkerboard(dest, x + q * 16, y, 16);
3816 }
3817 else if(InvalidBG == 1)
3818 {
3819 draw_static(dest, x, y, 256, 16);
3820 }
3821 else
3822 {
3823 rectfill(dest, x, y, x+255, y+15, vc(0));
3824 rect(dest, x, y, x+255, y+15, vc(15));
3825 line(dest, x, y, x+255, y+15, vc(15));
3826 line(dest, x, y+15, x+255, y, vc(15));
3827 }
3828 }
3829
3830 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3831 {
3832 for(int32_t i=0; i<176; i++)
3833 {
3834 word cmbdat = screens[TEMPLATE].data[i];
3835 byte cmbcset = screens[TEMPLATE].cset[i];
3836 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3837 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3838 }
3839 }
3840
3841 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3842 {
3843 for(int32_t i=0; i<176; i++)
3844 {
3845 word cmbdat = screens[TEMPLATE2].data[i];
3846 byte cmbcset = screens[TEMPLATE2].cset[i];
3847 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3848 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3849 }
3850 }
3851
3852 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3853 {
3854 word cmbdat = screens[TEMPLATE].data[pos];
3855 byte cmbcset = screens[TEMPLATE].cset[pos];
3856 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3857 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3858 }
3859
3860 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3861 {
3862 word cmbdat = screens[cursor.screen].secretcombo[scombo];
3863 byte cmbcset = screens[cursor.screen].secretcset[scombo];
3864 byte cmbflag = screens[cursor.screen].secretflag[scombo];
3865 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3866 }
3867
3868 void zmap::scroll(int32_t dir, bool warp)
3869 {
3870 if(cursor.map<map_count)
3871 {
3872 switch(dir)
3873 {
3874 case up:
3875 if(warp && Map.CurrScr()->flags2&wfUP)
3876 {
3877 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3878 }
3879 else if(cursor.screen>15)
3880 {
3881 setCurrScr(cursor.screen - 16);
3882 }
3883
3884 break;
3885
3886 case down:
3887 if(warp && Map.CurrScr()->flags2&wfDOWN)
3888 {
3889 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3890 }
3891 else if(cursor.screen<MAPSCRS-16)
3892 {
3893 setCurrScr(cursor.screen + 16);
3894 }
3895
3896 break;
3897
3898 case left:
3899 if(warp && Map.CurrScr()->flags2&wfLEFT)
3900 {
3901 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3902 }
3903 else if(cursor.screen&15)
3904 {
3905 setCurrScr(cursor.screen - 1);
3906 }
3907
3908 break;
3909
3910 case right:
3911 if(warp && Map.CurrScr()->flags2&wfRIGHT)
3912 {
3913 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
3914 }
3915 else if((cursor.screen&15)<15 && cursor.screen<MAPSCRS-1)
3916 {
3917 setCurrScr(cursor.screen + 1);
3918 }
3919
3920 break;
3921 }
3922 }
3923 }
3924
3925 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
3926 {
3927 switch(side)
3928 {
3929 case up:
3930 switch(door)
3931 {
3932 case dWALL:
3933 case dBOMB:
3934 case dWALK:
3935 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
3936 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
3937 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
3938 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
3939 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
3940 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
3941 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
3942 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
3943 break;
3944
3945 default:
3946 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
3947 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
3948 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
3949 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
3950 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
3951 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
3952 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
3953 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
3954 break;
3955 }
3956
3957 break;
3958
3959 case down:
3960 switch(door)
3961 {
3962 case dWALL:
3963 case dBOMB:
3964 case dWALK:
3965 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
3966 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
3967 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
3968 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
3969 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
3970 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
3971 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
3972 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
3973 break;
3974
3975 default:
3976 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
3977 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
3978 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
3979 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
3980 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
3981 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
3982 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
3983 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
3984 break;
3985 }
3986
3987 break;
3988
3989 case left:
3990 switch(door)
3991 {
3992 case dWALL:
3993 case dBOMB:
3994 case dWALK:
3995 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
3996 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
3997 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
3998 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
3999 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
4000 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4001 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4002 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4003 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4004 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4005 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4006 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4007 break;
4008
4009 default:
4010 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4011 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4012 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4013 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4014 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4015 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4016 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4017 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4018 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4019 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4020 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4021 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4022 break;
4023 }
4024
4025 break;
4026
4027 case right:
4028 switch(door)
4029 {
4030 case dWALL:
4031 case dBOMB:
4032 case dWALK:
4033 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4034 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4035 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4036 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4037 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4038 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4039 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4040 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4041 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4042 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4043 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4044 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4045 break;
4046
4047 default:
4048 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4049 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4050 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4051 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4052 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4053 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4054 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4055 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4056 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4057 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4058 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4059 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4060 break;
4061 }
4062
4063 break;
4064 }
4065 }
4066 void zmap::DoPutDoorCommand(int side, int door, bool force)
4067 {
4068 if(!force && screens[cursor.screen].door[side] == door)
4069 return;
4070 bool already_list = InListCommand();
4071 if(!already_list)
4072 StartListCommand();
4073 DoSetDoorCommand(cursor.screen,side,door);
4074 if(door != dNONE)
4075 {
4076 word data[176] = {0};
4077 byte cset[176] = {0};
4078 fetch_door(side, door, screens[cursor.screen].door_combo_set, data, cset);
4079 for(int q = 0; q < 176; ++q)
4080 if(data[q])
4081 DoSetComboCommand(cursor.map,cursor.screen,q,data[q],cset[q]);
4082 }
4083 if(!already_list)
4084 FinishListCommand();
4085 }
4086 void zmap::putdoor(int32_t screen,int32_t side,int32_t door)
4087 {
4088 if(screens[screen].door[side] == door)
4089 return;
4090
4091 screens[screen].door[side] = door;
4092 if(door != dNONE)
4093 {
4094 word data[176] = {0};
4095 byte cset[176] = {0};
4096 fetch_door(side, door, screens[screen].door_combo_set, data, cset);
4097 for(int q = 0; q < 176; ++q)
4098 if(data[q])
4099 {
4100 screens[screen].data[q] = data[q];
4101 screens[screen].cset[q] = cset[q];
4102 }
4103 }
4104 }
4105
4106 void list_command::execute()
4107 {
4108 for (auto command : commands)
4109 {
4110 command->execute();
4111 }
4112 }
4113
4114 void list_command::undo()
4115 {
4116 for (int i = commands.size() - 1; i >= 0; i--)
4117 {
4118 commands[i]->undo();
4119 }
4120 }
4121
4122 int list_command::size()
4123 {
4124 int s = 0;
4125 for (auto command : commands)
4126 {
4127 s += command->size();
4128 }
4129 return s;
4130 }
4131
4132 void set_combo_command::execute()
4133 {
4134 mapscr* scr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4135 if (!scr_ptr) return;
4136
4137 if (combo != -1) scr_ptr->data[pos] = combo;
4138 scr_ptr->cset[pos] = cset;
4139 }
4140
4141 void set_combo_command::undo()
4142 {
4143 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4144 if(!mapscr_ptr) return;
4145 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4146 mapscr_ptr->cset[pos] = prev_cset;
4147 }
4148
4149 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4150 {
4151 std::array<int, 8> initd_arr;
4152 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4153
4154 return {
4155 .x = ffc.x,
4156 .y = ffc.y,
4157 .vx = ffc.vx,
4158 .vy = ffc.vy,
4159 .ax = ffc.ax,
4160 .ay = ffc.ay,
4161 .data = ffc.data,
4162 .cset = ffc.cset,
4163 .delay = ffc.delay,
4164 .link = ffc.link,
4165 .script = ffc.script,
4166 .tw = ffc.txsz,
4167 .th = ffc.tysz,
4168 .ew = ffc.hit_width,
4169 .eh = ffc.hit_height,
4170 .flags = ffc.flags,
4171 .initd = initd_arr,
4172 .layer = ffc.layer
4173 };
4174 }
4175
4176 void set_ffc_command::execute()
4177 {
4178 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4179 if(!mapscr_ptr) return;
4180
4181 mapscr_ptr->valid |= mVALID;
4182 mapscr_ptr->ffcs[i].x = data.x;
4183 mapscr_ptr->ffcs[i].y = data.y;
4184 mapscr_ptr->ffcs[i].vx = data.vx;
4185 mapscr_ptr->ffcs[i].vy = data.vy;
4186 mapscr_ptr->ffcs[i].ax = data.ax;
4187 mapscr_ptr->ffcs[i].ay = data.ay;
4188 mapscr_ptr->ffcs[i].data = data.data;
4189 mapscr_ptr->ffcs[i].cset = data.cset;
4190 mapscr_ptr->ffcs[i].delay = data.delay;
4191 mapscr_ptr->ffcs[i].link = data.link;
4192 mapscr_ptr->ffcs[i].script = data.script;
4193 mapscr_ptr->ffcs[i].flags = data.flags;
4194 mapscr_ptr->ffEffectWidth(i, data.ew);
4195 mapscr_ptr->ffEffectHeight(i, data.eh);
4196 mapscr_ptr->ffTileWidth(i, data.tw);
4197 mapscr_ptr->ffTileHeight(i, data.th);
4198 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4199 mapscr_ptr->ffcs[i].layer = data.layer;
4200 mapscr_ptr->ffcCountMarkDirty();
4201 mapscr_ptr->ffcs[i].updateSolid();
4202 }
4203
4204 void set_ffc_command::undo()
4205 {
4206 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4207 if(!mapscr_ptr) return;
4208
4209 mapscr_ptr->ffcs[i].x = prev_data.x;
4210 mapscr_ptr->ffcs[i].y = prev_data.y;
4211 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4212 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4213 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4214 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4215 mapscr_ptr->ffcs[i].data = prev_data.data;
4216 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4217 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4218 mapscr_ptr->ffcs[i].link = prev_data.link;
4219 mapscr_ptr->ffcs[i].script = prev_data.script;
4220 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4221 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4222 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4223 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4224 mapscr_ptr->ffTileHeight(i, prev_data.th);
4225 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4226 mapscr_ptr->ffcs[i].layer = prev_data.layer;
4227 mapscr_ptr->ffcCountMarkDirty();
4228 mapscr_ptr->ffcs[i].updateSolid();
4229 }
4230
4231 void set_flag_command::execute()
4232 {
4233 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4234 if(!mapscr_ptr) return;
4235
4236 mapscr_ptr->valid |= mVALID;
4237 mapscr_ptr->sflag[pos] = flag;
4238 }
4239
4240 void set_flag_command::undo()
4241 {
4242 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4243 if(!mapscr_ptr) return;
4244 mapscr_ptr->sflag[pos] = prev_flag;
4245 }
4246
4247 void set_door_command::execute()
4248 {
4249 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4250 if(!mapscr_ptr) return;
4251
4252 mapscr_ptr->valid |= mVALID;
4253 mapscr_ptr->door[side] = door;
4254 }
4255
4256 void set_door_command::undo()
4257 {
4258 Map.AbsoluteScr(cursor.map, cursor.screen)->door[side] = prev_door;
4259 }
4260
4261 void set_dcs_command::execute()
4262 {
4263 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4264 if(!mapscr_ptr) return;
4265
4266 mapscr_ptr->valid |= mVALID;
4267 mapscr_ptr->door_combo_set = dcs;
4268 }
4269
4270 void set_dcs_command::undo()
4271 {
4272 Map.AbsoluteScr(cursor.map, cursor.screen)->door_combo_set = prev_dcs;
4273 }
4274
4275 void paste_screen_command::execute()
4276 {
4277 perform(screen.get());
4278 }
4279
4280 void paste_screen_command::undo()
4281 {
4282 if (prev_screens.size() > 1)
4283 {
4284 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4285 ASSERT(prev_screens.size() == 128);
4286 for (int i = 0; i < 128; i++)
4287 {
4288 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, i), prev_screens[i].get());
4289 // TODO: why not just this?
4290 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4291 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4292 }
4293 return;
4294 }
4295
4296 perform(prev_screens[0].get());
4297 }
4298
4299 int paste_screen_command::size()
4300 {
4301 return prev_screens.size() + 1;
4302 }
4303
4304 void paste_screen_command::perform(mapscr* to)
4305 {
4306 if (to)
4307 {
4308 switch (type) {
4309 case ScreenAll: Map.PasteAll(*to, screen_index); break;
4310 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4311 case ScreenData: Map.PasteScreenData(*to, screen_index); break;
4312 case ScreenDoors: Map.PasteDoors(*to, screen_index); break;
4313 case ScreenEnemies: Map.PasteEnemies(*to, screen_index); break;
4314 case ScreenFFCombos: Map.PasteFFCombos(*to, screen_index); break;
4315 case ScreenGuy: Map.PasteGuy(*to, screen_index); break;
4316 case ScreenLayers: Map.PasteLayers(*to, screen_index); break;
4317 case ScreenPalette: Map.PastePalette(*to, screen_index); break;
4318 case ScreenPartial: Map.Paste(*to, screen_index); break;
4319 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4320 case ScreenRoom: Map.PasteRoom(*to, screen_index); break;
4321 case ScreenSecretCombos: Map.PasteSecretCombos(*to, screen_index); break;
4322 case ScreenUnderCombo: Map.PasteUnderCombo(*to, screen_index); break;
4323 case ScreenWarpLocations: Map.PasteWarpLocations(*to, screen_index); break;
4324 case ScreenWarps: Map.PasteWarps(*to, screen_index); break;
4325 }
4326 }
4327 else
4328 {
4329 Map.clearscr(screen_index);
4330 }
4331 refresh(rALL);
4332 }
4333
4334 void set_screen_command::execute()
4335 {
4336 if (screen)
4337 {
4338 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), screen.get());
4339 }
4340 else
4341 {
4342 Map.clearscr(screen_index);
4343 }
4344 refresh(rALL);
4345 }
4346
4347 void set_screen_command::undo()
4348 {
4349 if (prev_screen)
4350 {
4351 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), prev_screen.get());
4352 }
4353 else
4354 {
4355 Map.clearscr(screen_index);
4356 }
4357 refresh(rALL);
4358 }
4359
4360 int set_screen_command::size()
4361 {
4362 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4363 }
4364
4365 static std::shared_ptr<list_command> current_list_command;
4366 void zmap::StartListCommand()
4367 {
4368 ASSERT(!current_list_command);
4369 current_list_command.reset(new list_command);
4370 }
4371
4372 void zmap::FinishListCommand()
4373 {
4374 if (current_list_command->commands.size() == 1)
4375 {
4376 input_undo_stack.push_back(current_list_command->commands[0]);
4377 }
4378 else if (current_list_command->commands.size() > 1)
4379 {
4380 input_undo_stack.push_back(current_list_command);
4381 }
4382 CapCommandHistory();
4383 current_list_command = nullptr;
4384 }
4385
4386 void zmap::RevokeListCommand()
4387 {
4388 current_list_command->undo();
4389 current_list_command = nullptr;
4390 }
4391
4392 bool zmap::InListCommand() const
4393 {
4394 return current_list_command ? true : false;
4395 }
4396
4397 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4398 {
4399 input_redo_stack = {};
4400
4401 if (!skip_execute) command->execute();
4402 if (current_list_command)
4403 {
4404 current_list_command->commands.push_back(command);
4405 if (current_list_command->commands.size() == 1)
4406 {
4407 current_list_command->cursor = command->cursor;
4408 }
4409 }
4410 else
4411 {
4412 input_undo_stack.push_back(command);
4413 CapCommandHistory();
4414 }
4415 mark_save_dirty();
4416 }
4417
4418 void zmap::UndoCommand()
4419 {
4420 if (input_undo_stack.size() <= 0) return;
4421
4422 // If not currently looking at the associated screen, first change the view
4423 // and wait for the next call to actually undo this command.
4424 auto command = input_undo_stack.back();
4425 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4426 {
4427 setCursor(command.get()->cursor);
4428 return;
4429 }
4430
4431 command->undo();
4432 input_redo_stack.push(command);
4433 input_undo_stack.pop_back();
4434 mark_save_dirty();
4435 }
4436
4437 void zmap::RedoCommand()
4438 {
4439 if (input_redo_stack.size() <= 0) return;
4440
4441 // If not currently selected the associated screen, first change the cursor
4442 // and wait for the next call to actually execute this command.
4443 auto command = input_redo_stack.top();
4444 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4445 {
4446 setCursor(command.get()->cursor);
4447 return;
4448 }
4449
4450 command->execute();
4451 input_undo_stack.push_back(command);
4452 input_redo_stack.pop();
4453 mark_save_dirty();
4454 }
4455
4456 11 void zmap::ClearCommandHistory()
4457 {
4458 11 current_list_command = nullptr;
4459 11 input_undo_stack = {};
4460 11 input_redo_stack = {};
4461 11 }
4462
4463 // Extra amount is from mapscr's vectors.
4464 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4465 // Allow the undo system to use roughly 100 MB of memory.
4466 // This doesn't count the memory used by commands that don't store a mapscr,
4467 // but that should be negligible.
4468 12 static int max_command_size = 100e6 / size_of_mapscr;
4469 void zmap::CapCommandHistory()
4470 {
4471 int size;
4472 do
4473 {
4474 size = 0;
4475 for (auto command : input_undo_stack)
4476 {
4477 size += command->size();
4478 }
4479 if (size > max_command_size) input_undo_stack.pop_front();
4480 } while (size > max_command_size);
4481 }
4482
4483 void zmap::DoSetComboCommand(ComboPosition pos, int combo, int cset)
4484 {
4485 if (!pos.is_valid(cursor))
4486 return;
4487
4488 int map = cursor.map;
4489 int screen = cursor.viewscr + pos.screen_offset();
4490 if (!AbsoluteScr(map, screen))
4491 return;
4492
4493 if (CurrentLayer)
4494 {
4495 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4496 map = scr->layermap[CurrentLayer-1]-1;
4497 screen = scr->layerscreen[CurrentLayer-1];
4498 }
4499 DoSetComboCommand(map, screen, pos.truncate(), combo, cset);
4500 }
4501
4502 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4503 {
4504 mapscr* mapscr_ptr = AbsoluteScrMakeValid(map, scr);
4505 if (!mapscr_ptr) return;
4506
4507 std::shared_ptr<set_combo_command> command(new set_combo_command);
4508 command->cursor = cursor;
4509 command->map = map;
4510 command->scr = scr;
4511 command->pos = pos;
4512 command->combo = combo;
4513 command->cset = cset;
4514 command->prev_combo = mapscr_ptr->data[pos];
4515 command->prev_cset = mapscr_ptr->cset[pos];
4516 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4517 {
4518 // nothing to do...
4519 return;
4520 }
4521
4522 ExecuteCommand(command);
4523 }
4524
4525 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4526 {
4527 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4528 if(!mapscr_ptr) return;
4529
4530 mapscr_ptr->ensureFFC(i);
4531
4532 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4533
4534 std::array<int, 8> initd_arr;
4535 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4536
4537 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4538
4539 command->cursor = cursor;
4540 command->map = map;
4541 command->scr = scr;
4542 command->i = i;
4543 command->data = data;
4544 command->prev_data = prev_data;
4545 if (data == prev_data)
4546 {
4547 // nothing to do...
4548 return;
4549 }
4550
4551 ExecuteCommand(command);
4552 }
4553
4554 void zmap::DoSetFlagCommand(ComboPosition pos, int flag)
4555 {
4556 if (!pos.is_valid(cursor))
4557 return;
4558
4559 int map = cursor.map;
4560 int screen = cursor.viewscr + pos.screen_offset();
4561 if (!AbsoluteScr(map, screen))
4562 return;
4563
4564 if (CurrentLayer)
4565 {
4566 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4567 map = scr->layermap[CurrentLayer-1]-1;
4568 screen = scr->layerscreen[CurrentLayer-1];
4569 }
4570 DoSetFlagCommand(map, screen, pos.truncate(), flag);
4571 }
4572
4573 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4574 {
4575 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4576 if(!mapscr_ptr) return;
4577
4578 std::shared_ptr<set_flag_command> command(new set_flag_command);
4579 command->cursor = cursor;
4580 command->map = map;
4581 command->scr = scr;
4582 command->pos = pos;
4583 command->flag = flag;
4584 command->prev_flag = mapscr_ptr->sflag[pos];
4585 if (command->flag == command->prev_flag)
4586 {
4587 // nothing to do...
4588 return;
4589 }
4590
4591 ExecuteCommand(command);
4592 }
4593
4594 void zmap::DoSetDoorCommand(int scr, int side, int door)
4595 {
4596 if(screens[scr].door[side] == door)
4597 return;
4598 std::shared_ptr<set_door_command> command(new set_door_command);
4599 command->cursor = cursor;
4600 command->side = side;
4601 command->door = door;
4602 command->prev_door = screens[scr].door[side];
4603
4604 ExecuteCommand(command);
4605 }
4606 void zmap::DoSetDCSCommand(int dcs)
4607 {
4608 if(screens[cursor.screen].door_combo_set == dcs)
4609 return;
4610 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4611 command->cursor = cursor;
4612 command->dcs = dcs;
4613 command->prev_dcs = screens[cursor.screen].door_combo_set;
4614
4615 ExecuteCommand(command);
4616 }
4617
4618 void zmap::DoPasteScreenCommand(PasteCommandType type, int screen)
4619 {
4620 if (screen == -1)
4621 screen = cursor.screen;
4622
4623 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4624 command->cursor = cursor;
4625 command->type = type;
4626 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4627 command->screen_index = screen;
4628
4629 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4630 {
4631 for (int i=0; i < 128; i++)
4632 {
4633 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4634 }
4635 }
4636 else
4637 {
4638 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[screen])));
4639 }
4640
4641 ExecuteCommand(command);
4642 }
4643
4644 void zmap::DoClearScreenCommand(int screen)
4645 {
4646 std::shared_ptr<set_screen_command> command(new set_screen_command);
4647 command->cursor = cursor;
4648 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[screen]));
4649 command->screen = std::shared_ptr<mapscr>(nullptr);
4650 command->screen_index = screen;
4651
4652 ExecuteCommand(command);
4653 }
4654
4655 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int screen)
4656 {
4657 std::shared_ptr<set_screen_command> command(new set_screen_command);
4658 command->cursor = cursor;
4659 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4660 Template(floorcombo, floorcset, screen);
4661 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4662
4663 ExecuteCommand(command, true);
4664 }
4665
4666 void zmap::Copy(int scr)
4667 {
4668 if(screens[scr].valid&mVALID)
4669 {
4670 copy_mapscr(&copymapscr, &screens[scr]);
4671 //copymapscr=screens[scr];
4672 can_paste=true;
4673 copymap=cursor.map;
4674 copyscr=scr;
4675 copyscrdata = zinit.screen_data[cursor.map*MAPSCRS+scr];
4676 copyffc = -1;
4677 }
4678 }
4679
4680 void zmap::CopyFFC(int32_t screen, int32_t n)
4681 {
4682 if(screens[screen].valid&mVALID)
4683 {
4684 copy_mapscr(&copymapscr, &screens[screen]);
4685 // Can't paste the screen itself
4686 can_paste = false;
4687 copymap=cursor.map;
4688 copyscr=screen;
4689 copyffc = n;
4690 }
4691 }
4692
4693 void zmap::Paste(const mapscr& copymapscr, int screen)
4694 {
4695 if(can_paste)
4696 {
4697 if(!(screens[screen].valid&mVALID))
4698 {
4699 screens[screen].valid |= mVALID;
4700 screens[screen].color = copymapscr.color;
4701 }
4702
4703 screens[screen].door_combo_set = copymapscr.door_combo_set;
4704
4705 for(int32_t i=0; i<4; i++)
4706 {
4707 screens[screen].door[i]=copymapscr.door[i];
4708 }
4709
4710 for(int32_t i=0; i<176; i++)
4711 {
4712 screens[screen].data[i] = copymapscr.data[i];
4713 screens[screen].cset[i] = copymapscr.cset[i];
4714 screens[screen].sflag[i] = copymapscr.sflag[i];
4715 }
4716
4717 refresh_color();
4718
4719 mark_save_dirty();
4720 }
4721 }
4722
4723 void zmap::PasteUnderCombo(const mapscr& copymapscr, int screen)
4724 {
4725 if(can_paste)
4726 {
4727 screens[screen].undercombo = copymapscr.undercombo;
4728 screens[screen].undercset = copymapscr.undercset;
4729 mark_save_dirty();
4730 }
4731 }
4732
4733 void zmap::PasteSecretCombos(const mapscr& copymapscr, int screen)
4734 {
4735 if(can_paste)
4736 {
4737 for(int32_t i=0; i<128; i++)
4738 {
4739 screens[screen].secretcombo[i] = copymapscr.secretcombo[i];
4740 screens[screen].secretcset[i] = copymapscr.secretcset[i];
4741 screens[screen].secretflag[i] = copymapscr.secretflag[i];
4742 }
4743
4744 mark_save_dirty();
4745 }
4746 }
4747
4748 // TODO const mapscr& copymapscr
4749 void zmap::PasteFFCombos(mapscr& copymapscr, int screen)
4750 {
4751 if(can_paste)
4752 {
4753 screens[screen].ffcs = copymapscr.ffcs;
4754 screens[screen].ffcCountMarkDirty();
4755 mark_save_dirty();
4756 }
4757 }
4758
4759 void zmap::PasteWarps(const mapscr& copymapscr, int screen)
4760 {
4761 if(can_paste)
4762 {
4763 screens[screen].sidewarpindex = copymapscr.sidewarpindex;
4764
4765 for(int32_t i=0; i<4; i++)
4766 {
4767 screens[screen].tilewarptype[i] = copymapscr.tilewarptype[i];
4768 screens[screen].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4769 screens[screen].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4770 screens[screen].sidewarptype[i] = copymapscr.sidewarptype[i];
4771 screens[screen].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4772 screens[screen].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4773 screens[screen].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4774 screens[screen].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4775 screens[screen].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4776 screens[screen].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4777 }
4778
4779 mark_save_dirty();
4780 }
4781 }
4782
4783 void zmap::PasteScreenData(const mapscr& copymapscr, int screen)
4784 {
4785 if(can_paste)
4786 {
4787 screens[screen].csensitive = copymapscr.csensitive;
4788 screens[screen].oceansfx = copymapscr.oceansfx;
4789 screens[screen].bosssfx = copymapscr.bosssfx;
4790 screens[screen].secretsfx = copymapscr.secretsfx;
4791 screens[screen].holdupsfx = copymapscr.holdupsfx;
4792 screens[screen].flags = copymapscr.flags;
4793 screens[screen].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4794 screens[screen].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4795 screens[screen].flags3 = copymapscr.flags3;
4796 screens[screen].flags4 = copymapscr.flags4;
4797 screens[screen].flags5 = copymapscr.flags5;
4798 screens[screen].flags6 = copymapscr.flags6;
4799 screens[screen].flags7 = copymapscr.flags7;
4800 screens[screen].flags8 = copymapscr.flags8;
4801 screens[screen].flags9 = copymapscr.flags9;
4802 screens[screen].flags10 = copymapscr.flags10;
4803 screens[screen].flags11 = copymapscr.flags11;
4804 screens[screen].item = copymapscr.item;
4805 screens[screen].hasitem = copymapscr.hasitem;
4806 screens[screen].itemx = copymapscr.itemx;
4807 screens[screen].itemy = copymapscr.itemy;
4808 screens[screen].nextmap = copymapscr.nextmap;
4809 screens[screen].nextscr = copymapscr.nextscr;
4810 screens[screen].nocarry = copymapscr.nocarry;
4811 screens[screen].noreset = copymapscr.noreset;
4812 screens[screen].exstate_reset = copymapscr.exstate_reset;
4813 screens[screen].exstate_carry = copymapscr.exstate_carry;
4814 screens[screen].path[0] = copymapscr.path[0];
4815 screens[screen].path[1] = copymapscr.path[1];
4816 screens[screen].path[2] = copymapscr.path[2];
4817 screens[screen].path[3] = copymapscr.path[3];
4818 screens[screen].pattern = copymapscr.pattern;
4819 screens[screen].exitdir = copymapscr.exitdir;
4820 screens[screen].screen_midi = copymapscr.screen_midi;
4821 screens[screen].stairx = copymapscr.stairx;
4822 screens[screen].stairy = copymapscr.stairy;
4823 screens[screen].timedwarptics = copymapscr.timedwarptics;
4824 mark_save_dirty();
4825 }
4826 }
4827
4828 void zmap::PasteWarpLocations(const mapscr& copymapscr, int screen)
4829 {
4830 if(can_paste)
4831 {
4832 screens[screen].warpreturnc = copymapscr.warpreturnc;
4833 screens[screen].warparrivalx = copymapscr.warparrivalx;
4834 screens[screen].warparrivaly = copymapscr.warparrivaly;
4835
4836 for(int32_t i=0; i<4; i++)
4837 {
4838 screens[screen].warpreturnx[i] = copymapscr.warpreturnx[i];
4839 screens[screen].warpreturny[i] = copymapscr.warpreturny[i];
4840 }
4841
4842 mark_save_dirty();
4843 }
4844 }
4845
4846 void zmap::PasteDoors(const mapscr& copymapscr, int screen)
4847 {
4848 if(can_paste)
4849 {
4850 for(int32_t i=0; i<4; i++)
4851 screens[screen].door[i] = copymapscr.door[i];
4852
4853 screens[screen].door_combo_set = copymapscr.door_combo_set;
4854 mark_save_dirty();
4855 }
4856 }
4857
4858 void zmap::PasteLayers(const mapscr& copymapscr, int screen)
4859 {
4860 if(can_paste)
4861 {
4862 for(int32_t i=0; i<6; i++)
4863 {
4864 screens[screen].layermap[i] = copymapscr.layermap[i];
4865 screens[screen].layerscreen[i] = copymapscr.layerscreen[i];
4866 screens[screen].layeropacity[i] = copymapscr.layeropacity[i];
4867 }
4868
4869 mark_save_dirty();
4870 }
4871 }
4872
4873 void zmap::PasteRoom(const mapscr& copymapscr, int screen)
4874 {
4875 if(can_paste)
4876 {
4877 screens[screen].room = copymapscr.room;
4878 screens[screen].catchall = copymapscr.catchall;
4879 mark_save_dirty();
4880 }
4881 }
4882
4883 void zmap::PasteGuy(const mapscr& copymapscr, int screen)
4884 {
4885 if(can_paste)
4886 {
4887 screens[screen].guy = copymapscr.guy;
4888 screens[screen].guytile = copymapscr.guytile;
4889 screens[screen].guycs = copymapscr.guycs;
4890 SETFLAG(screens[screen].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4891 SETFLAG(screens[screen].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4892 screens[screen].str = copymapscr.str;
4893 mark_save_dirty();
4894 }
4895 }
4896
4897 void zmap::PastePalette(const mapscr& copymapscr, int screen)
4898 {
4899 if(can_paste)
4900 {
4901 screens[screen].color = copymapscr.color;
4902 screens[screen].valid|=mVALID;
4903 refresh_color();
4904
4905 mark_save_dirty();
4906 }
4907 }
4908
4909 void zmap::PasteAll(const mapscr& copymapscr, int screen)
4910 {
4911 if(can_paste)
4912 {
4913 copy_mapscr(&screens[screen], &copymapscr);
4914 zinit.screen_data[cursor.map*MAPSCRS+cursor.screen] = copyscrdata;
4915 screens[screen].valid|=mVALID;
4916
4917 refresh_color();
4918
4919 mark_save_dirty();
4920 }
4921 }
4922
4923
4924 void zmap::PasteToAll(const mapscr& copymapscr)
4925 {
4926 if(can_paste)
4927 {
4928 for(int32_t x=0; x<128; x++)
4929 {
4930 if(!(screens[x].valid&mVALID))
4931 {
4932 screens[x].valid |= mVALID;
4933 screens[x].color = copymapscr.color;
4934 }
4935
4936 for(int32_t i=0; i<176; i++)
4937 {
4938 screens[x].data[i] = copymapscr.data[i];
4939 screens[x].cset[i] = copymapscr.cset[i];
4940 screens[x].sflag[i] = copymapscr.sflag[i];
4941 }
4942 }
4943
4944 refresh_color();
4945
4946 mark_save_dirty();
4947 }
4948 }
4949
4950 void zmap::PasteAllToAll(const mapscr& copymapscr)
4951 {
4952 if(can_paste)
4953 {
4954 for(int32_t x=0; x<128; x++)
4955 {
4956 copy_mapscr(&screens[x], &copymapscr);
4957 zinit.screen_data[cursor.map*MAPSCRS+x] = copyscrdata;
4958 //screens[x]=copymapscr;
4959 }
4960
4961 refresh_color();
4962
4963 mark_save_dirty();
4964 }
4965 }
4966
4967 void zmap::PasteEnemies(const mapscr& copymapscr, int screen)
4968 {
4969 if(can_paste)
4970 {
4971 for(int32_t i=0; i<10; i++)
4972 screens[screen].enemy[i]=copymapscr.enemy[i];
4973 }
4974 }
4975
4976 bool zmap::CanGoBack() const
4977 {
4978 return !cursor_undo_stack.empty();
4979 }
4980
4981 bool zmap::CanGoForward() const
4982 {
4983 return !cursor_redo_stack.empty();
4984 }
4985
4986 void zmap::GoBack()
4987 {
4988 if (!CanGoBack())
4989 return;
4990
4991 cursor_redo_stack.push(cursor);
4992
4993 ConfigureCursorHistory(false);
4994 setCursor(cursor_undo_stack.back());
4995 ConfigureCursorHistory(true);
4996
4997 cursor_undo_stack.pop_back();
4998 }
4999
5000 void zmap::GoForward()
5001 {
5002 if (!CanGoForward())
5003 return;
5004
5005 cursor_undo_stack.push_back(cursor);
5006
5007 ConfigureCursorHistory(false);
5008 setCursor(cursor_redo_stack.top());
5009 ConfigureCursorHistory(true);
5010
5011 cursor_redo_stack.pop();
5012 }
5013
5014 void zmap::CapCursorHistory()
5015 {
5016 int max_history_size = 1000;
5017 while (cursor_undo_stack.size() > max_history_size)
5018 cursor_undo_stack.pop_front();
5019 }
5020
5021 void zmap::ConfigureCursorHistory(bool enable)
5022 {
5023 cursor_history_enabled = enable;
5024 }
5025
5026 void zmap::setCopyFFC(int32_t n)
5027 {
5028 copyffc = n;
5029 }
5030
5031 void zmap::update_combo_cycling()
5032 {
5033 if(!prv_mode||!prv_cmbcycle)
5034 {
5035 return;
5036 }
5037
5038 int32_t x;
5039 int32_t newdata[176];
5040 int32_t newcset[176];
5041 bool restartanim[MAXCOMBOS] = {0};
5042
5043 for(int32_t i=0; i<176; i++)
5044 {
5045 newdata[i]=-1;
5046 newcset[i]=-1;
5047
5048 x=prvscr.data[i];
5049
5050 //time to restart
5051 if((combobuf[x].aclk>=combobuf[x].speed) &&
5052 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5053 combobuf[x].can_cycle())
5054 {
5055 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5056 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5057
5058 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5059 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5060 int32_t c = newdata[i];
5061
5062 if(combobuf[c].animflags & AF_CYCLE)
5063 {
5064 restartanim[c]=true;
5065 }
5066 }
5067 }
5068
5069 for(int32_t i=0; i<176; i++)
5070 {
5071 x=prvscr.data[i];
5072
5073 //time to restart
5074 if((combobuf[x].aclk>=combobuf[x].speed) &&
5075 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5076 combobuf[x].can_cycle())
5077 {
5078 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5079 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5080
5081 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5082 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5083 int32_t c = newdata[i];
5084
5085 if(combobuf[c].animflags & AF_CYCLE)
5086 {
5087 restartanim[c]=true;
5088 }
5089 }
5090 }
5091
5092 for(int32_t i=0; i<176; i++)
5093 {
5094 if(newdata[i]==-1)
5095 continue;
5096
5097 prvscr.data[i]=newdata[i];
5098 prvscr.cset[i]=newcset[i];
5099 }
5100
5101 word maxffc = prvscr.numFFC();
5102 for(word i=0; i<maxffc; i++)
5103 {
5104 ffcdata& ffc = prvscr.ffcs[i];
5105 newcombo const& cmb = combobuf[ffc.data];
5106
5107 //time to restart
5108 if((cmb.aclk>=cmb.speed) &&
5109 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5110 cmb.can_cycle())
5111 {
5112 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
5113 ffc.data = cycle_under ? prvscr.undercombo : cmb.nextcombo;
5114
5115 if(!(cmb.animflags & AF_CYCLENOCSET))
5116 newcset[i] = cycle_under ? prvscr.undercset : cmb.nextcset;
5117
5118 if(combobuf[ffc.data].animflags & AF_CYCLE)
5119 {
5120 restartanim[ffc.data]=true;
5121 }
5122 prvscr.ffcs[i].data = ffc.data;
5123 prvscr.ffcs[i].cset=ffc.cset;
5124 }
5125 }
5126
5127
5128 if(get_qr(qr_CMBCYCLELAYERS))
5129 {
5130 for(int32_t j=0; j<6; j++)
5131 {
5132 if(!prvlayers[j].valid)
5133 continue;
5134
5135 for(int32_t i=0; i<176; i++)
5136 {
5137 newdata[i]=-1;
5138 newcset[i]=-1;
5139
5140 x=(prvlayers[j]).data[i];
5141
5142 //time to restart
5143 if((combobuf[x].aclk>=combobuf[x].speed) &&
5144 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5145 combobuf[x].can_cycle())
5146 {
5147 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5148 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5149
5150 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5151 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5152 int32_t c = newdata[i];
5153
5154 if(combobuf[c].animflags & AF_CYCLE)
5155 {
5156 restartanim[c]=true;
5157 }
5158 }
5159 }
5160
5161 for(int32_t i=0; i<176; i++)
5162 {
5163 x=(prvlayers[j]).data[i];
5164
5165 //time to restart
5166 if((combobuf[x].aclk>=combobuf[x].speed) &&
5167 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5168 combobuf[x].can_cycle())
5169 {
5170 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5171 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5172
5173 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5174 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5175 int32_t c = newdata[i];
5176
5177 if(combobuf[c].animflags & AF_CYCLE)
5178 {
5179 restartanim[c]=true;
5180 }
5181 }
5182 }
5183
5184 for(int32_t i=0; i<176; i++)
5185 {
5186 if(newdata[i]==-1)
5187 continue;
5188
5189 prvlayers[j].data[i]=newdata[i];
5190 prvlayers[j].cset[i]=newcset[i];
5191 }
5192 }
5193 }
5194
5195 for(int32_t i=0; i<MAXCOMBOS; i++)
5196 {
5197 if(restartanim[i])
5198 {
5199 combobuf[i].tile = combobuf[i].o_tile;
5200 combobuf[i].cur_frame=0;
5201 combobuf[i].aclk = 0;
5202 }
5203 }
5204 }
5205
5206 void zmap::update_freeform_combos()
5207 {
5208 if(!prv_mode||!prv_cmbcycle)
5209 {
5210 return;
5211 }
5212
5213 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5214 word maxffc = prvscr.numFFC();
5215 for(int32_t i=0; i<maxffc; i++)
5216 {
5217 if(!(prvscr.ffcs[i].flags&ffc_changer) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffc_stationary))
5218 {
5219 for(int32_t j=0; j<maxffc; j++)
5220 {
5221 if(i!=j)
5222 {
5223 if(prvscr.ffcs[j].flags&ffc_changer && prvscr.ffcs[j].data != 0)
5224 {
5225 if((((prvscr.ffcs[j].x.getInt())!=prvscr.ffcs[i].changer_x)||((prvscr.ffcs[j].y.getInt())!=prvscr.ffcs[i].changer_y))&&(prvscr.ffcs[i].link==0))
5226 {
5227 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),prvscr.ffcs[i].prev_changer_x,prvscr.ffcs[i].prev_changer_y,prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5228 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(prvscr.ffcs[i].prev_changer_x>-10000000&&prvscr.ffcs[i].prev_changer_y>-10000000))
5229 {
5230 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5231 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5232 if(prvscr.ffcs[j].flags&ffc_changethis)
5233 {
5234 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5235 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5236 }
5237
5238 if(prvscr.ffcs[j].flags&ffc_changenext)
5239 prvscr.ffcs[i].data += 1;
5240
5241 if(prvscr.ffcs[j].flags&ffc_changeprev)
5242 prvscr.ffcs[i].data -= 1;
5243
5244 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5245 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5246 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5247
5248 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5249 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5250 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5251 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5252
5253 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5254 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5255 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5256 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5257 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5258
5259 if(prvscr.ffcs[i].flags&ffc_carryover)
5260 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffc_carryover;
5261 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5262
5263 prvscr.ffcs[i].flags&=~ffc_changer;
5264 prvscr.ffcs[i].changer_x=(prvscr.ffcs[j].x.getInt());
5265 prvscr.ffcs[i].changer_y=(prvscr.ffcs[j].y.getInt());
5266
5267 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5268 {
5269 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5270 }
5271
5272 if((prvscr.ffcs[j].flags&ffc_swapnext)||(prvscr.ffcs[j].flags&ffc_swapprev))
5273 {
5274 int32_t k=0;
5275
5276 if(prvscr.ffcs[j].flags&ffc_swapnext)
5277 k=j<(MAXFFCS-1)?j+1:0;
5278
5279 if(prvscr.ffcs[j].flags&ffc_swapprev)
5280 k=j>0?j-1:(MAXFFCS-1);
5281
5282 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5283 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5284 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5285 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5286 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5287 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5288 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5289 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5290 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5291 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5292 }
5293 }
5294 }
5295 }
5296 }
5297 }
5298
5299 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5300 {
5301 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5302 {
5303 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5304 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5305 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5306 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5307 }
5308 else
5309 {
5310 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5311 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5312 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5313 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5314 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5315 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5316
5317 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5318 {
5319 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5320
5321 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5322
5323 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5324
5325 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5326 }
5327 }
5328 }
5329 else
5330 {
5331 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5332 prvscr.ffcs[i].delay--;
5333 }
5334
5335 if(prvscr.ffcs[i].x<-32)
5336 {
5337 if(prvscr.flags6&fWRAPAROUNDFF)
5338 {
5339 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5340 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5341 }
5342 else
5343 {
5344 prvscr.ffcs[i].data = 0;
5345 prvscr.ffcs[i].flags&=~ffc_carryover;
5346 }
5347 }
5348
5349 if(prvscr.ffcs[i].y<-32)
5350 {
5351 if(prvscr.flags6&fWRAPAROUNDFF)
5352 {
5353 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5354 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5355 }
5356 else
5357 {
5358 prvscr.ffcs[i].data = 0;
5359 prvscr.ffcs[i].flags&=~ffc_carryover;
5360 }
5361 }
5362
5363 if(prvscr.ffcs[i].x>=288)
5364 {
5365 if(prvscr.flags6&fWRAPAROUNDFF)
5366 {
5367 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5368 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5369 }
5370 else
5371 {
5372 prvscr.ffcs[i].data = 0;
5373 prvscr.ffcs[i].flags&=~ffc_carryover;
5374 }
5375 }
5376
5377 if(prvscr.ffcs[i].y>=208)
5378 {
5379 if(prvscr.flags6&fWRAPAROUNDFF)
5380 {
5381 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5382 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].x.getZLong();
5383 }
5384 else
5385 {
5386 prvscr.ffcs[i].data = 0;
5387 prvscr.ffcs[i].flags&=~ffc_carryover;
5388 }
5389 }
5390
5391 }
5392 }
5393 }
5394
5395 void zmap::goto_dmapscr(int dmap, int scr)
5396 {
5397 goto_mapscr(DMaps[dmap].map, scr + DMaps[dmap].xoff);
5398 }
5399 void zmap::goto_mapscr(int map, int scr)
5400 {
5401 auto new_cursor = cursor;
5402 new_cursor.map = map;
5403 new_cursor.setScreen(scr);
5404 setCursor(std::move(new_cursor));
5405 }
5406
5407 void zmap::dowarp(int32_t type, int32_t index)
5408 {
5409 set_warpback();
5410 if(type==0)
5411 {
5412
5413 int32_t dmap=screens[cursor.screen].tilewarpdmap[index];
5414 int32_t scr=screens[cursor.screen].tilewarpscr[index];
5415
5416 switch(screens[cursor.screen].tilewarptype[index])
5417 {
5418 case wtCAVE:
5419 case wtNOWARP:
5420 break;
5421
5422 default:
5423 goto_dmapscr(dmap, scr);
5424 break;
5425 }
5426 }
5427 else if(type==1)
5428 {
5429 int32_t dmap=screens[cursor.screen].sidewarpdmap[index];
5430 int32_t scr=screens[cursor.screen].sidewarpscr[index];
5431
5432 switch(screens[cursor.screen].sidewarptype[index])
5433 {
5434 case wtCAVE:
5435 case wtNOWARP:
5436 break;
5437
5438 default:
5439 goto_dmapscr(dmap, scr);
5440 break;
5441 }
5442 }
5443 }
5444
5445 extern int32_t prv_twon;
5446
5447 void zmap::prv_dowarp(int32_t type, int32_t index)
5448 {
5449 if(type==0)
5450 {
5451
5452 int32_t dmap=prvscr.tilewarpdmap[index];
5453 int32_t scr=prvscr.tilewarpscr[index];
5454
5455 switch(prvscr.tilewarptype[index])
5456 {
5457 case wtCAVE:
5458 case wtNOWARP:
5459 break;
5460
5461 default:
5462 //setCurrMap(DMaps[dmap].map);
5463 //setCurrScr(scr+DMaps[dmap].xoff);
5464 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5465 refresh_color();
5466 //prv_cmbcycle=0;
5467 break;
5468 }
5469 }
5470 else if(type==1)
5471 {
5472 int32_t dmap=prvscr.sidewarpdmap[index];
5473 int32_t scr=prvscr.sidewarpscr[index];
5474
5475 switch(prvscr.sidewarptype[index])
5476 {
5477 case wtCAVE:
5478 case wtNOWARP:
5479 break;
5480
5481 default:
5482 //setCurrMap(DMaps[dmap].map);
5483 //setCurrScr(scr+DMaps[dmap].xoff);
5484 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5485 refresh_color();
5486 //prv_cmbcycle=0;
5487 break;
5488 }
5489 }
5490
5491 if(prv_twon)
5492 {
5493 prv_time=get_prvscr()->timedwarptics;
5494 }
5495 }
5496
5497 void zmap::dowarp2(int32_t ring,int32_t index)
5498 {
5499 set_warpback();
5500 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5501 }
5502
5503 void zmap::set_warpback()
5504 {
5505 warpbackmap = cursor.map;
5506 warpbackscreen = cursor.screen;
5507 }
5508 bool zmap::has_warpback()
5509 {
5510 return warpbackmap && warpbackscreen
5511 && !(warpbackmap == cursor.map && warpbackscreen == cursor.screen);
5512 }
5513 void zmap::warpback()
5514 {
5515 if(!has_warpback())
5516 return;
5517
5518 int m = cursor.map, s = cursor.screen;
5519 goto_mapscr(*warpbackmap, *warpbackscreen);
5520 warpbackmap = m;
5521 warpbackscreen = s;
5522 }
5523
5524 bool save_msgstrs(const char *path)
5525 {
5526 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5527
5528 if(!f)
5529 {
5530 return false;
5531 }
5532
5533 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5534 {
5535 pack_fclose(f);
5536 return true;
5537 }
5538
5539 pack_fclose(f);
5540 return false;
5541 }
5542
5543 1 bool save_strings_tsv(const char *path)
5544 {
5545 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5546
5547
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5548 {
5549 return false;
5550 }
5551
5552
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5553 {
5554 1 pack_fclose(f);
5555 1 return true;
5556 }
5557
5558 pack_fclose(f);
5559 return false;
5560 1 }
5561
5562 bool save_msgstrs_text(const char *path)
5563 {
5564 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5565
5566 if(!f)
5567 {
5568 return false;
5569 }
5570
5571 if(writestrings_text(f)==0)
5572 {
5573 pack_fclose(f);
5574 return true;
5575 }
5576
5577 pack_fclose(f);
5578 return false;
5579 }
5580
5581 bool load_msgstrs(const char *path, int32_t startstring)
5582 {
5583 //these are here to bypass compiler warnings about unused arguments
5584 startstring=startstring;
5585
5586 dword section_id;
5587 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5588
5589 if(!f)
5590 {
5591 return false;
5592 }
5593
5594 if(!p_mgetl(&section_id,f))
5595 {
5596 return false;
5597 }
5598
5599 if(section_id==ID_STRINGS)
5600 {
5601 if(readstrings(f, &header)==0)
5602 {
5603 pack_fclose(f);
5604 return true;
5605 }
5606 else
5607 {
5608 pack_fclose(f);
5609 return false;
5610 }
5611 }
5612
5613 pack_fclose(f);
5614 return false;
5615 }
5616
5617 bool load_strings_tsv(const char *path)
5618 {
5619 try
5620 {
5621 parse_strings_tsv(util::read_text_file(path));
5622 }
5623 catch (std::exception& ex)
5624 {
5625 InfoDialog("Import .tsv Error", ex.what()).show();
5626 return false;
5627 }
5628 return true;
5629 }
5630
5631 bool save_pals(const char *path)
5632 {
5633 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5634
5635 if(!f)
5636 {
5637 return false;
5638 }
5639
5640 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5641 {
5642 pack_fclose(f);
5643 return true;
5644 }
5645
5646 pack_fclose(f);
5647 return false;
5648 }
5649
5650 bool load_pals(const char *path, int32_t startcset)
5651 {
5652 dword section_id;
5653 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5654
5655 if(!f)
5656 {
5657 return false;
5658 }
5659
5660 if(!p_mgetl(&section_id,f))
5661 {
5662 return false;
5663 }
5664
5665 if(section_id==ID_CSETS)
5666 {
5667 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5668 {
5669 pack_fclose(f);
5670 loadlvlpal(Color);
5671 return true;
5672 }
5673 else
5674 {
5675 pack_fclose(f);
5676 return false;
5677 }
5678 }
5679
5680 return false;
5681 }
5682
5683 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5684 bool save_guys(const char *path)
5685 {
5686 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5687
5688 if(!f)
5689 {
5690 return false;
5691 }
5692
5693 /*
5694 int32_t id = ID_GUYS;
5695 if(!p_mputl(id,f))
5696 {
5697 return false;
5698 }
5699 */
5700
5701 zquestheader h;
5702 h.zelda_version = 0x250;
5703 h.build = 21;
5704
5705 if(writeguys(f, &h)==0)
5706 {
5707 pack_fclose(f);
5708 return true;
5709 }
5710
5711 pack_fclose(f);
5712 return false;
5713 }
5714
5715 bool load_guys(const char *path)
5716 {
5717 dword section_id;
5718 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5719
5720 if(!f)
5721 {
5722 return false;
5723 }
5724
5725 if(!p_mgetl(&section_id,f))
5726 {
5727 pack_fclose(f);
5728 return false;
5729 }
5730
5731 zquestheader h;
5732 h.zelda_version = 0x250;
5733 h.build = 21;
5734
5735 if(section_id==ID_GUYS)
5736 {
5737 if(readguys(f, &h)==0)
5738 {
5739 pack_fclose(f);
5740 return true;
5741 }
5742 }
5743
5744 pack_fclose(f);
5745 return false;
5746 }
5747
5748
5749 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5750 bool save_combo_alias(const char *path)
5751 {
5752 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5753
5754 if(!f)
5755 {
5756 return false;
5757 }
5758
5759 zquestheader h;
5760 h.zelda_version = 0x250;
5761 h.build = 21;
5762
5763 if(writecomboaliases(f, 0, 0)==0)
5764 {
5765 pack_fclose(f);
5766 return true;
5767 }
5768
5769 pack_fclose(f);
5770 return false;
5771 }
5772
5773 bool load_combo_alias(const char *path)
5774 {
5775 dword section_id;
5776 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5777
5778 if(!f)
5779 {
5780 return false;
5781 }
5782
5783 if(!p_mgetl(&section_id,f))
5784 {
5785 pack_fclose(f);
5786 return false;
5787 }
5788
5789 zquestheader h;
5790 h.zelda_version = 0x250;
5791 h.build = 21;
5792
5793 if(section_id==ID_COMBOALIASES)
5794 {
5795 if(readcomboaliases(f, &h, 0, 0)==0)
5796 {
5797 pack_fclose(f);
5798 return true;
5799 }
5800 }
5801
5802 pack_fclose(f);
5803 return false;
5804 }
5805
5806 bool load_zgp(const char *path)
5807 {
5808 dword section_id;
5809 word section_version;
5810 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5811
5812 if(!f)
5813 return false;
5814
5815 if(!p_mgetl(&section_id,f))
5816 {
5817 pack_fclose(f);
5818 return false;
5819 }
5820
5821 if(section_id!=ID_GRAPHICSPACK)
5822 {
5823 pack_fclose(f);
5824 return false;
5825 }
5826
5827 //section version info
5828 if(!p_igetw(&section_version,f))
5829 {
5830 return 2;
5831 }
5832
5833 if(!read_deprecated_section_cversion(f))
5834 {
5835 return 3;
5836 }
5837
5838 //tiles
5839 if(!p_mgetl(&section_id,f))
5840 {
5841 pack_fclose(f);
5842 return false;
5843 }
5844
5845 if(section_id==ID_TILES)
5846 {
5847 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
5848 {
5849 pack_fclose(f);
5850 init_tiles(true, &header);
5851 return false;
5852 }
5853 }
5854 else
5855 {
5856 pack_fclose(f);
5857 return false;
5858 }
5859
5860 //combos
5861 if(!p_mgetl(&section_id,f))
5862 {
5863 pack_fclose(f);
5864 return false;
5865 }
5866
5867 if(section_id==ID_COMBOS)
5868 {
5869 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
5870 {
5871 pack_fclose(f);
5872 return false;
5873 }
5874 }
5875 else
5876 {
5877 pack_fclose(f);
5878 return false;
5879 }
5880
5881 //palettes
5882 if(!p_mgetl(&section_id,f))
5883 {
5884 pack_fclose(f);
5885 return false;
5886 }
5887
5888 if(section_id==ID_CSETS)
5889 {
5890 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
5891 {
5892 pack_fclose(f);
5893 return false;
5894 }
5895 }
5896 else
5897 {
5898 pack_fclose(f);
5899 return false;
5900 }
5901
5902 //items
5903 if(!p_mgetl(&section_id,f))
5904 {
5905 pack_fclose(f);
5906 return false;
5907 }
5908
5909 if(section_id==ID_ITEMS)
5910 {
5911 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
5912 {
5913 pack_fclose(f);
5914 return false;
5915 }
5916 }
5917 else
5918 {
5919 pack_fclose(f);
5920 return false;
5921 }
5922
5923 //weapons
5924 if(!p_mgetl(&section_id,f))
5925 {
5926 pack_fclose(f);
5927 return false;
5928 }
5929
5930 if(section_id==ID_WEAPONS)
5931 {
5932 if(readweapons(f, &header)!=0)
5933 {
5934 pack_fclose(f);
5935 return false;
5936 }
5937 }
5938 else
5939 {
5940 pack_fclose(f);
5941 return false;
5942 }
5943
5944 //read the triforce pieces info and make sure it worked
5945 //really do this?
5946
5947 //read the game icons info and make sure it worked
5948 if(!p_mgetl(&section_id,f))
5949 {
5950 pack_fclose(f);
5951 return false;
5952 }
5953
5954 if(section_id==ID_ICONS)
5955 {
5956 if(readgameicons(f, &header, &QMisc)!=0)
5957 {
5958 pack_fclose(f);
5959 return false;
5960 }
5961 }
5962 else
5963 {
5964 pack_fclose(f);
5965 return false;
5966 }
5967
5968 //read the misc colors info and map styles info and make sure it worked
5969 if(!p_mgetl(&section_id,f))
5970 {
5971 pack_fclose(f);
5972 return false;
5973 }
5974
5975 if(section_id==ID_COLORS)
5976 {
5977 if(readmisccolors(f, &header, &QMisc)!=0)
5978 {
5979 pack_fclose(f);
5980 return false;
5981 }
5982 }
5983 else
5984 {
5985 pack_fclose(f);
5986 return false;
5987 }
5988
5989 //read the door combo sets and make sure it worked
5990 if(!p_mgetl(&section_id,f))
5991 {
5992 pack_fclose(f);
5993 return false;
5994 }
5995
5996 if(section_id==ID_DOORS)
5997 {
5998 if(readdoorcombosets(f, &header)!=0)
5999 {
6000 pack_fclose(f);
6001 return false;
6002 }
6003 }
6004 else
6005 {
6006 pack_fclose(f);
6007 return false;
6008 }
6009
6010 //read the template screens and make sure it worked
6011 //really do this?
6012
6013 //yay! it worked! close the file and say everything was ok.
6014 loadlvlpal(Color);
6015 setup_combo_animations();
6016 setup_combo_animations2();
6017 pack_fclose(f);
6018 return true;
6019 }
6020
6021 bool save_zgp(const char *path)
6022 {
6023 reset_combo_animations();
6024 reset_combo_animations2();
6025
6026 //open the file
6027 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6028
6029 if(!f)
6030 return false;
6031
6032 dword section_id=ID_GRAPHICSPACK;
6033 dword section_version=V_GRAPHICSPACK;
6034
6035 //section id
6036 if(!p_mputl(section_id,f))
6037 {
6038 return 1;
6039 }
6040
6041 //section version info
6042 if(!p_iputw(section_version,f))
6043 {
6044 return 2;
6045 }
6046
6047 if(!write_deprecated_section_cversion(section_version,f))
6048 {
6049 return 3;
6050 }
6051
6052 //tiles
6053 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6054 {
6055 pack_fclose(f);
6056 return false;
6057 }
6058
6059 //combos
6060 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6061 {
6062 pack_fclose(f);
6063 return false;
6064 }
6065
6066 //palettes
6067 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6068 {
6069 pack_fclose(f);
6070 return false;
6071 }
6072
6073 //items
6074 if(writeitems(f, &header)!=0)
6075 {
6076 pack_fclose(f);
6077 return false;
6078 }
6079
6080 //weapons
6081 if(writeweapons(f, &header)!=0)
6082 {
6083 pack_fclose(f);
6084 return false;
6085 }
6086
6087 //write the triforce pieces info and make sure it worked
6088 //really do this?
6089
6090 //write the game icons info and make sure it worked
6091 if(writegameicons(f, &header)!=0)
6092 {
6093 pack_fclose(f);
6094 return false;
6095 }
6096
6097 //write the misc colors info and map styles info and make sure it worked
6098 if(writemisccolors(f, &header)!=0)
6099 {
6100 pack_fclose(f);
6101 return false;
6102 }
6103
6104 //write the door combo sets and make sure it worked
6105 if(writedoorcombosets(f, &header)!=0)
6106 {
6107 pack_fclose(f);
6108 return false;
6109 }
6110
6111 //write the template screens and make sure it worked
6112 //really do this?
6113
6114 pack_fclose(f);
6115 return true;
6116 }
6117
6118 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6119 {
6120 //open the file
6121 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6122
6123 if(!f)
6124 return false;
6125
6126 dword section_id=ID_SUBSCREEN;
6127 dword s_version=V_SUBSCREEN;
6128
6129 if(!p_mputl(section_id,f))
6130 {
6131 pack_fclose(f);
6132 return false;
6133 }
6134
6135 if(!p_iputw(s_version,f))
6136 {
6137 pack_fclose(f);
6138 return false;
6139 }
6140
6141 if(!write_deprecated_section_cversion(s_version,f))
6142 {
6143 pack_fclose(f);
6144 return false;
6145 }
6146
6147 if(savefrom.write(f))
6148 {
6149 pack_fclose(f);
6150 return false;
6151 }
6152
6153 pack_fclose(f);
6154 return true;
6155 }
6156
6157 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6158 {
6159 //open the file
6160 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6161
6162 if(!f)
6163 return false;
6164
6165 dword section_id;
6166 dword s_version;
6167
6168 if(!p_mgetl(&section_id,f))
6169 {
6170 pack_fclose(f);
6171 return false;
6172 }
6173
6174 if(section_id!=ID_SUBSCREEN)
6175 {
6176 pack_fclose(f);
6177 return false;
6178 }
6179
6180 if(!p_igetw(&s_version,f))
6181 {
6182 pack_fclose(f);
6183 return false;
6184 }
6185
6186 if (s_version > V_SUBSCREEN)
6187 return qe_version;
6188
6189 if(!read_deprecated_section_cversion(f))
6190 {
6191 pack_fclose(f);
6192 return false;
6193 }
6194
6195 if(s_version < 8)
6196 {
6197 subscreen_group g;
6198 memset(&g,0,sizeof(subscreen_group));
6199 if(read_one_old_subscreen(f,&g,s_version)!=0)
6200 {
6201 pack_fclose(f);
6202 return false;
6203 }
6204 if(g.ss_type != loadto.sub_type)
6205 {
6206 pack_fclose(f);
6207 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6208 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6209 return false;
6210 }
6211 loadto.clear();
6212 if(g.objects[0].type != ssoNULL)
6213 loadto.load_old(g);
6214 }
6215 else
6216 {
6217 ZCSubscreen tmp = ZCSubscreen();
6218 if (tmp.read(f, s_version))
6219 {
6220 pack_fclose(f);
6221 return false;
6222 }
6223 if(tmp.sub_type != loadto.sub_type)
6224 {
6225 pack_fclose(f);
6226 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6227 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6228 return false;
6229 }
6230 loadto.clear();
6231 loadto = tmp;
6232 }
6233
6234 pack_fclose(f);
6235 return true;
6236 }
6237
6238 bool setMapCount2(int32_t c)
6239 {
6240 int32_t oldmapcount=map_count;
6241 int32_t cur_map=Map.getCurrMap();
6242
6243 bound(c,1,MAXMAPS);
6244 map_count=c;
6245
6246 try
6247 {
6248 TheMaps.resize(c*MAPSCRS);
6249 Map.force_refr_pointer();
6250 map_infos.resize(c);
6251 }
6252 catch(...)
6253 {
6254 jwin_alert("Error","Failed to change map count.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6255 return false;
6256 }
6257
6258 bound(cur_map,0,c-1);
6259 if(map_count>oldmapcount)
6260 {
6261 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6262 {
6263 // copy the default palette to the new maps
6264 map_infos[mc].autopalette = map_infos[cur_map].autopalette;
6265
6266 Map.setCurrMap(mc);
6267 for(int32_t ms=0; ms<MAPSCRS; ms++)
6268 Map.clearscr(ms);
6269 }
6270 Map.setCurrMap(cur_map);
6271 }
6272 else
6273 {
6274 Map.setCurrMap(cur_map);
6275 if(!layers_valid(Map.CurrScr()))
6276 fix_layers(Map.CurrScr(), false);
6277
6278 for(int32_t i=0; i<MAXDMAPS; i++)
6279 {
6280 if(DMaps[i].map>=map_count)
6281 {
6282 DMaps[i].map=map_count-1;
6283 }
6284 }
6285 }
6286
6287 return true;
6288 }
6289
6290 extern BITMAP *bmap;
6291
6292 static bool loading_file_new = false;
6293 int32_t init_quest(std::string tileset_path)
6294 {
6295 if (tileset_path.empty())
6296 tileset_path = DEFAULT_TILESET;
6297
6298 loading_file_new = true;
6299 load_quest(tileset_path.c_str());
6300 loading_file_new = false;
6301
6302 set_window_title("ZC Editor - Untitled Quest");
6303 zinit.last_map = 0;
6304 zinit.last_screen = 0;
6305
6306 if(bmap != NULL)
6307 {
6308 destroy_bitmap(bmap);
6309 bmap=NULL;
6310 }
6311
6312 return 0;
6313 }
6314
6315 void set_questpwd(std::string_view pwd, bool use_keyfile)
6316 {
6317 header.use_keyfile=use_keyfile;
6318
6319 // string_view actually has some quirks that make it less than ideal here.
6320 // It'd probably be best to replace it, but this works for now.
6321 memset(header.password, 0, 256);
6322 strcpy(header.password, pwd.data());
6323 header.dirty_password=true;
6324
6325 cvs_MD5Context ctx;
6326 cvs_MD5Init(&ctx);
6327 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6328 cvs_MD5Final(header.pwd_hash, &ctx);
6329 }
6330
6331
6332 bool is_null_pwd_hash(uint8_t *pwd_hash)
6333 {
6334 cvs_MD5Context ctx;
6335 uint8_t md5sum[16];
6336 char pwd[2]="";
6337
6338 cvs_MD5Init(&ctx);
6339 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6340 cvs_MD5Final(md5sum, &ctx);
6341
6342 return (memcmp(md5sum,pwd_hash,16)==0);
6343 }
6344
6345 static DIALOG pwd_dlg[] =
6346 {
6347 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6348 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6349 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6350 // 2 (filename)
6351 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6352 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6353 // 4 (challenge hash)
6354 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6355 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6356 // 6 (password)
6357 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6358 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6359 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6360 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6361 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6362 };
6363
6364 int32_t reverse_string(char* str)
6365 {
6366
6367 if(NULL==str)
6368 {
6369 return -1; //no string
6370 }
6371
6372 int32_t l=(int32_t)strlen(str)-1; //get the string length
6373
6374 if(1==l)
6375 {
6376 return 1;
6377 }
6378
6379 char c;
6380
6381 for(int32_t x=0; x < l; x++,l--)
6382 {
6383 c = str[x];
6384 str[x] = str[l];
6385 str[l] = c;
6386 }
6387
6388 return 0;
6389 }
6390
6391 #ifdef __GNUC__
6392 #pragma GCC diagnostic push
6393 #pragma GCC diagnostic ignored "-Wunreachable-code"
6394 #endif
6395
6396 11 int32_t quest_access(const char *filename, zquestheader *hdr)
6397 {
6398
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (is_headless())
6399 11 return 1;
6400
6401 #ifdef __EMSCRIPTEN__
6402 return 1;
6403 #endif
6404
6405 //Protection against compiling a release version with password protection off.
6406 static bool passguard = false;
6407
6408 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6409 #define MUST_HAVE_PASSWORD
6410 passguard = true;
6411 #endif
6412
6413 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6414 #if (defined _MSC_VER || defined _NPASS)
6415 return 1;
6416 #endif
6417 #endif
6418 if(devpwd()) return 1;
6419
6420 char hash_string[33];
6421
6422 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6423 {
6424 return 1;
6425 }
6426
6427 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6428 return true;
6429
6430 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6431 pwd_dlg[2].dp=get_filename(filename);
6432 cvs_MD5Context ctx;
6433 uint8_t md5sum[16]={0};
6434 char response[33]="";
6435 char prompt[256]="";
6436
6437 memcpy(md5sum, hdr->pwd_hash, 16);
6438
6439 for(int32_t i=0; i<300; ++i)
6440 {
6441 for(int32_t j=0; j<16; ++j)
6442 {
6443 sprintf(response+j*2, "%02x", md5sum[j]);
6444 }
6445
6446 if(i&1)
6447 {
6448 reverse_string(response);
6449 }
6450
6451 if(i==149)
6452 {
6453 strcpy(hash_string, response);
6454 }
6455
6456 cvs_MD5Init(&ctx);
6457 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6458 cvs_MD5Final(md5sum, &ctx);
6459 }
6460
6461 pwd_dlg[4].dp=hash_string;
6462
6463 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6464 {
6465 sprintf(prompt,"%s",response);
6466 }
6467
6468 pwd_dlg[6].dp=prompt;
6469
6470 large_dialog(pwd_dlg);
6471
6472 int32_t cancel = do_zqdialog(pwd_dlg,6);
6473
6474 if(cancel == 8)
6475 return 2;
6476
6477 bool ret=check_questpwd(hdr, prompt);
6478
6479 if(!ret)
6480 {
6481 ret=(strcmp(response,prompt)==0);
6482 }
6483 return ret ? 1 : 0;
6484 11 }
6485
6486 void set_rules(byte* newrules);
6487 11 void popup_bugfix_dlg(const char* cfg, byte* dest_qrs)
6488 {
6489 11 bool dont_show_again = zc_get_config("zquest",cfg,0);
6490
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 if(!dont_show_again && hasCompatRulesEnabled())
6491 {
6492
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
33 AlertDialog("Apply New Bugfixes",
6493
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 "New bugfixes found that can be applied to this quest!"
6494 "\nWould you like to apply them?"
6495 "\n(Applies 'Bugfix' rule template, un-checking compat rules)",
6496 11 [&](bool ret,bool dsa)
6497 {
6498 if(ret)
6499 {
6500 applyRuleTemplate(ruletemplateFixCompat,dest_qrs);
6501 }
6502 if(dsa)
6503 {
6504 zc_set_config("zquest",cfg,1);
6505 }
6506 },
6507
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 "Yes","No",
6508 0,false, //timeout - none
6509 true //"Don't show this again"
6510
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 ).show();
6511 11 }
6512 11 }
6513
6514 #ifdef __GNUC__
6515 #pragma GCC diagnostic pop
6516 #endif
6517
6518 11 int32_t load_quest(const char *filename, bool show_progress)
6519 {
6520 11 zq_freeze_all_rti();
6521
6522 char buf[2048];
6523 byte skip_flags[4];
6524
6525 11 dword tileset_flags = 0;
6526
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 11 times.
55 for(int32_t i=0; i<4; ++i)
6527 {
6528 44 skip_flags[i]=0;
6529 44 }
6530
2/2
✓ Branch 0 taken 7634 times.
✓ Branch 1 taken 11 times.
7645 for(int32_t i=0; i<qr_MAX; i++)
6531 7634 set_qr(i,0);
6532 11 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags,1,true,0,tileset_flags);
6533
6534
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ret!=qe_OK)
6535 {
6536 init_quest(DEFAULT_TILESET);
6537 }
6538 else
6539 {
6540 11 int32_t accessret = quest_access(filename, &header);
6541
6542
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(accessret != 1)
6543 {
6544 init_quest(DEFAULT_TILESET);
6545
6546 if(accessret == 0)
6547 ret=qe_pwd;
6548 else
6549 ret=qe_cancel;
6550 }
6551 else
6552 {
6553 11 Map.clear();
6554
6555
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 std::string qst_cfg_header = qst_cfg_header_from_path(filename);
6556
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 int view_size = zc_get_config(qst_cfg_header.c_str(), "zoom_num_screens", 1);
6557
6558
4/8
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
11 Map.setCursor(MapCursor{
6559
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 .map = vbound(zinit.last_map, 0, map_count - 1),
6560 11 .screen = zinit.last_screen,
6561 11 .viewscr = zinit.last_screen,
6562 11 .size = view_size,
6563 });
6564
6565 extern int32_t current_mappage;
6566 11 current_mappage = 0;
6567 11 bool found_default = false;
6568
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 83 times.
92 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6569 {
6570 83 auto &pg = map_page[q];
6571
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 2 times.
83 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6572 {
6573 2 current_mappage = q;
6574 2 break;
6575 }
6576
4/8
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
81 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6577 72 continue;
6578 else
6579 {
6580 9 current_mappage = q;
6581 9 found_default = true;
6582 }
6583 9 }
6584
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh(rALL);
6585
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh_pal();
6586
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 set_rules(quest_rules);
6587 11 saved = true;
6588
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
11 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6589
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 popup_bugfix_dlg("dsa_compatrule",nullptr);
6590
6591
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(bmap != NULL)
6592 {
6593 destroy_bitmap(bmap);
6594 bmap=NULL;
6595 }
6596
6597
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (show_progress)
6598 {
6599 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6600 set_window_title(buf);
6601 }
6602 11 }
6603 }
6604
6605 11 Map.ClearCommandHistory();
6606
6607
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!is_headless())
6608 {
6609 void load_size_poses();
6610 load_size_poses();
6611 }
6612
6613 11 return ret;
6614 }
6615
6616 int32_t load_tileset(const char *filename, dword tsetflags)
6617 {
6618 zq_freeze_all_rti();
6619
6620 byte skip_flags[4];
6621
6622 for(int32_t i=0; i<4; ++i)
6623 skip_flags[i]=0;
6624 for(int32_t i=0; i<qr_MAX; i++)
6625 set_qr(i,0);
6626 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6627
6628 if(ret!=qe_OK)
6629 init_quest(DEFAULT_TILESET);
6630 else
6631 {
6632 if(tsetflags & TILESET_BUGFIX)
6633 applyRuleTemplate(ruletemplateFixCompat);
6634 if(tsetflags & TILESET_SCR_BUGFIX)
6635 applyRuleTemplate(ruletemplateFixZSCompat);
6636
6637 int32_t accessret = quest_access(filename, &header);
6638
6639 if(accessret != 1)
6640 {
6641 init_quest(DEFAULT_TILESET);
6642
6643 if(accessret == 0)
6644 ret=qe_pwd;
6645 else
6646 ret=qe_cancel;
6647 }
6648 else
6649 {
6650 Map.clear();
6651 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6652 Map.setCurrScr(zinit.last_screen);
6653 extern int32_t current_mappage;
6654 current_mappage = 0;
6655 bool found_default = false;
6656 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6657 {
6658 auto &pg = map_page[q];
6659 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6660 {
6661 current_mappage = q;
6662 break;
6663 }
6664 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6665 continue;
6666 else
6667 {
6668 current_mappage = q;
6669 found_default = true;
6670 }
6671 }
6672 refresh(rALL);
6673 refresh_pal();
6674 set_rules(quest_rules);
6675
6676 if(bmap != NULL)
6677 {
6678 destroy_bitmap(bmap);
6679 bmap=NULL;
6680 }
6681
6682 set_window_title("ZC Editor - Untitled Quest");
6683 first_save = false;
6684 mark_save_dirty();
6685 memset(filepath,0,255);
6686 memset(temppath,0,255);
6687 }
6688 }
6689
6690 Map.ClearCommandHistory();
6691
6692 return ret;
6693 }
6694
6695 272730 int32_t write_weap_data(weapon_data const& data, PACKFILE* f)
6696 {
6697
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if(!p_iputw(V_WEAP_DATA,f))
6698 new_return(1);
6699
6700
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.flags, f))
6701 new_return(2);
6702
6703
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.moveflags, f))
6704 new_return(3);
6705
6706
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.wflags, f))
6707 new_return(4);
6708
6709
2/2
✓ Branch 0 taken 1363650 times.
✓ Branch 1 taken 272730 times.
1636380 for (int32_t q = 0; q < WPNSPR_MAX; ++q)
6710 {
6711
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.burnsprs[q], f))
6712 new_return(5);
6713
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.light_rads[q], f))
6714 new_return(6);
6715 1363650 }
6716
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.glow_shape, f))
6717 new_return(7);
6718
6719
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.override_flags, f))
6720 new_return(8);
6721
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tilew, f))
6722 new_return(9);
6723
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tileh, f))
6724 new_return(10);
6725
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxsz, f))
6726 new_return(11);
6727
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hysz, f))
6728 new_return(12);
6729
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hzsz, f))
6730 new_return(13);
6731
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxofs, f))
6732 new_return(14);
6733
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hyofs, f))
6734 new_return(15);
6735
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.xofs, f))
6736 new_return(16);
6737
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.yofs, f))
6738 new_return(17);
6739
6740
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.step, f))
6741 new_return(18);
6742
6743
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.unblockable, f))
6744 new_return(19);
6745
6746
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.timeout, f))
6747 new_return(20);
6748
6749
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.imitate_weapon, f))
6750 new_return(21);
6751
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.default_defense, f))
6752 new_return(22);
6753
6754
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_level, f))
6755 new_return(23);
6756
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_time, f))
6757 new_return(24);
6758
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.lift_height, f))
6759 new_return(25);
6760
6761
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.script, f))
6762 new_return(26);
6763
2/2
✓ Branch 0 taken 2181840 times.
✓ Branch 1 taken 272730 times.
2454570 for(uint q = 0; q < 8; ++q)
6764
1/2
✓ Branch 0 taken 2181840 times.
✗ Branch 1 not taken.
2181840 if(!p_iputl(data.initd[q], f))
6765 new_return(27);
6766
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.pierce_count, f))
6767 new_return(28);
6768 272730 return 0;
6769 }
6770
6771 130 bool write_midi(MIDI *m,PACKFILE *f)
6772 {
6773 int32_t c;
6774
6775
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
130 if(!p_mputw(m->divisions,f)) return false;
6776
6777
2/2
✓ Branch 0 taken 4160 times.
✓ Branch 1 taken 130 times.
4290 for(c=0; c<MIDI_TRACKS; c++)
6778 {
6779
1/2
✓ Branch 0 taken 4160 times.
✗ Branch 1 not taken.
4160 if(!p_mputl(m->track[c].len,f)) return false;
6780
6781
2/2
✓ Branch 0 taken 2896 times.
✓ Branch 1 taken 1264 times.
4160 if(m->track[c].len > 0)
6782 {
6783
1/2
✓ Branch 0 taken 1264 times.
✗ Branch 1 not taken.
1264 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6784 return false;
6785 1264 }
6786 4160 }
6787
6788 130 return true;
6789 130 }
6790
6791 9 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6792 {
6793 9 dword section_id=ID_HEADER;
6794 9 dword section_version=V_HEADER;
6795 9 dword section_size=0;
6796
6797 //file header string
6798
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6799 {
6800 new_return(1);
6801 }
6802
6803 //section id
6804
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
6805 {
6806 new_return(2);
6807 }
6808
6809 //section version info
6810
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
6811 {
6812 new_return(3);
6813 }
6814
6815
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
6816 {
6817 new_return(4);
6818 }
6819
6820
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6821 {
6822 18 fake_pack_writing=(writecycle==0);
6823
6824 //section size
6825
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
6826 {
6827 new_return(5);
6828 }
6829
6830 18 writesize=0;
6831
6832 //finally... section data
6833
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->zelda_version,f))
6834 {
6835 new_return(6);
6836 }
6837
6838
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->build,f))
6839 {
6840 new_return(7);
6841 }
6842
6843
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6844 {
6845 new_return(8);
6846 }
6847
6848
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->internal,f))
6849 {
6850 new_return(10);
6851 }
6852
6853
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->quest_number,f))
6854 {
6855 new_return(11);
6856 }
6857
6858
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->version,16,f))
6859 {
6860 new_return(12);
6861 }
6862
6863
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->minver,16,f))
6864 {
6865 new_return(13);
6866 }
6867
6868
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->title,sizeof(Header->title),f))
6869 {
6870 new_return(14);
6871 }
6872
6873
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->author,sizeof(Header->author),f))
6874 {
6875 new_return(15);
6876 }
6877
6878
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->use_keyfile,f))
6879 {
6880 new_return(16);
6881 }
6882
6883
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
6884 {
6885 new_return(17);
6886 }
6887
6888
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
6889 {
6890 new_return(19);
6891 }
6892
6893
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(0,f)) //why are we doing this?
6894 //this is for map count, it seems. -Z
6895 {
6896 new_return(20);
6897 }
6898
6899 18 auto version = getVersion();
6900
6901
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.major,f))
6902 {
6903 new_return(21);
6904 }
6905
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.minor,f))
6906 {
6907 new_return(22);
6908 }
6909
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.patch,f))
6910 {
6911 new_return(23);
6912 }
6913 // Fourth component is deprecated.
6914
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6915 {
6916 new_return(24);
6917 }
6918
6919 // Numerous prerelease stages is deprecated.
6920
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6921 {
6922 new_return(25);
6923 }
6924
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6925 {
6926 new_return(26);
6927 }
6928
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6929 {
6930 new_return(27);
6931 }
6932
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6933 {
6934 new_return(28);
6935 }
6936
6937
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(BUILDTM_YEAR,f))
6938 {
6939 new_return(29);
6940 }
6941
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MONTH,f))
6942 {
6943 new_return(30);
6944 }
6945
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_DAY,f))
6946 {
6947 new_return(31);
6948 }
6949
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_HOUR,f))
6950 {
6951 new_return(32);
6952 }
6953
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MINUTE,f))
6954 {
6955 new_return(33);
6956 }
6957
6958 // This is no longer set to anything.
6959 const char* tempsig[256];
6960 18 memset(tempsig, 0, 256);
6961
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempsig,256,f))
6962 {
6963 new_return(34);
6964 }
6965
6966 char tempcompilersig[256];
6967 18 memset(tempcompilersig, 0, 256);
6968 18 strcpy(tempcompilersig, COMPILER_NAME);
6969
6970
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilersig,256,f))
6971 {
6972 new_return(35);
6973 }
6974
6975 char tempcompilerversion[256];
6976 18 memset(tempcompilerversion, 0, 256);
6977 #ifdef _MSC_VER
6978 zc_itoa(_MSC_VER,tempcompilerversion,10);
6979 #else
6980 18 strcpy(tempcompilerversion, COMPILER_VERSION);
6981 #endif
6982
6983
6984
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilerversion,256,f))
6985 {
6986 new_return(36);
6987 }
6988
6989
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite("ZQuest Classic",1024,f))
6990 {
6991 new_return(37);
6992 }
6993
6994 // V_ZC_COMPILERSIG - a deprecated version field.
6995
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(1,f))
6996 {
6997 new_return(38);
6998 }
6999 #ifdef _MSC_VER
7000 if(!p_iputl((_MSC_VER / 100),f))
7001 {
7002 new_return(39);
7003 }
7004 #else
7005
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FIRST,f))
7006 {
7007 new_return(39);
7008 }
7009 #endif
7010
7011
7012
7013 #ifdef _MSC_VER
7014 if(!p_iputl((_MSC_VER % 100),f))
7015 {
7016 new_return(41);
7017 }
7018 #else
7019
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_SECOND,f))
7020 {
7021 new_return(41);
7022 }
7023 #endif
7024
7025 #ifdef _MSC_VER
7026 # if _MSC_VER >= 1400
7027 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7028 {
7029 new_return(40);
7030 }
7031 # else
7032 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7033 {
7034 new_return(40);
7035 }
7036 #endif
7037 #else
7038
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_THIRD,f))
7039 {
7040 new_return(40);
7041 }
7042 #endif
7043
7044 #ifdef _MSC_VER
7045 if(!p_iputl((_MSC_BUILD),f))
7046 {
7047 new_return(42);
7048 }
7049 #else
7050
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FOURTH,f))
7051 {
7052 new_return(42);
7053 }
7054 #endif
7055
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7056 {
7057 new_return(43);
7058 }
7059
7060 // Modules were removed (replaced by zinfo).
7061 char tempmodulename[1024];
7062 18 memset(tempmodulename, 0, 1024);
7063
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempmodulename,1024,f))
7064 {
7065 new_return(44);
7066 }
7067
7068 char tempdate[256];
7069 18 memset(tempdate, 0, 256);
7070 18 strcpy(tempdate, __DATE__);
7071
7072
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempdate,256,f))
7073 {
7074 new_return(45);
7075 }
7076 char temptime[256];
7077 18 memset(temptime, 0, 256);
7078 18 strcpy(temptime, __TIME__);
7079
7080
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptime,256,f))
7081 {
7082 new_return(46);
7083 }
7084
7085
7086 char temptimezone[6];
7087 18 memset(temptimezone, 0, 6);
7088 18 strcpy(temptimezone, __TIMEZONE__);
7089
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptimezone,6,f))
7090 {
7091 new_return(47);
7092 }
7093
7094
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7095 {
7096 new_return(48);
7097 }
7098
7099
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(isStableRelease() ? 0 : 1, f))
7100 {
7101 new_return(49);
7102 }
7103
7104
3/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
18 if(!p_putcstr(version.version_string, f))
7105 {
7106 new_return(50);
7107 }
7108
7109
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7110 {
7111 9 section_size=writesize;
7112 9 }
7113 18 }
7114
7115
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7116 {
7117 char ebuf[80];
7118 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7119 jwin_alert("Error: writeheader()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7120 }
7121
7122 9 new_return(0);
7123 }
7124
7125 9 int32_t writerules(PACKFILE *f, zquestheader *Header)
7126 {
7127 //these are here to bypass compiler warnings about unused arguments
7128 9 Header=Header;
7129
7130 9 dword section_id=ID_RULES;
7131 9 dword section_version=V_RULES;
7132 9 dword section_size=0;
7133
7134 //section id
7135
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7136 {
7137 new_return(1);
7138 }
7139
7140 //section version info
7141
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7142 {
7143 new_return(2);
7144 }
7145
7146
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7147 {
7148 new_return(3);
7149 }
7150
7151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!p_iputl(V_COMPATRULE,f))
7152 {
7153 new_return(6);
7154 }
7155
7156
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7157 {
7158 18 fake_pack_writing=(writecycle==0);
7159
7160 //section size
7161
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7162 {
7163 new_return(4);
7164 }
7165
7166 18 writesize=0;
7167
7168 //finally... section data
7169
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7170 {
7171 new_return(5);
7172 }
7173
7174
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7175 {
7176 9 section_size=writesize;
7177 9 }
7178 18 }
7179
7180
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7181 {
7182 char ebuf[80];
7183 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7184 jwin_alert("Error: writerules()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7185 }
7186
7187 9 new_return(0);
7188 }
7189
7190
7191 9 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7192 {
7193 //these are here to bypass compiler warnings about unused arguments
7194 9 Header=Header;
7195
7196 9 dword section_id=ID_DOORS;
7197 9 dword section_version=V_DOORS;
7198 9 dword section_size=0;
7199
7200 //section id
7201
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7202 {
7203 new_return(1);
7204 }
7205
7206 //section version info
7207
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7208 {
7209 new_return(2);
7210 }
7211
7212
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7213 {
7214 new_return(3);
7215 }
7216
7217
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7218 {
7219 18 fake_pack_writing=(writecycle==0);
7220
7221 //section size
7222
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7223 {
7224 new_return(4);
7225 }
7226
7227 18 writesize=0;
7228
7229 //finally... section data
7230
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(door_combo_set_count,f))
7231 {
7232 new_return(5);
7233 }
7234
7235
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 18 times.
338 for(int32_t i=0; i<door_combo_set_count; i++)
7236 {
7237 //name
7238 char name[21];
7239 320 memset(name, 21, (char)0);
7240 320 strcpy(name, DoorComboSetNames[i].c_str());
7241
1/2
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
320 if(!pfwrite(name,sizeof(name),f))
7242 {
7243 new_return(6);
7244 }
7245
7246 //up door
7247
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7248 {
7249
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7250 {
7251
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7252 {
7253 new_return(7);
7254 }
7255 11520 }
7256 2880 }
7257
7258
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7259 {
7260
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7261 {
7262
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7263 {
7264 new_return(8);
7265 }
7266 11520 }
7267 2880 }
7268
7269 //down door
7270
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7271 {
7272
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7273 {
7274
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7275 {
7276 new_return(9);
7277 }
7278 11520 }
7279 2880 }
7280
7281
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7282 {
7283
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7284 {
7285
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7286 {
7287 new_return(10);
7288 }
7289 11520 }
7290 2880 }
7291
7292
7293 //left door
7294
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7295 {
7296
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7297 {
7298
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7299
7300 {
7301 new_return(11);
7302 }
7303 17280 }
7304 2880 }
7305
7306
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7307 {
7308
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7309 {
7310
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7311 {
7312 new_return(12);
7313 }
7314 17280 }
7315 2880 }
7316
7317 //right door
7318
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7319 {
7320
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7321 {
7322
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7323 {
7324 new_return(13);
7325 }
7326 17280 }
7327 2880 }
7328
7329
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7330 {
7331
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7332 {
7333
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7334 {
7335 new_return(14);
7336 }
7337 17280 }
7338 2880 }
7339
7340
7341 //up bomb rubble
7342
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7343 {
7344
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7345 {
7346 new_return(15);
7347 }
7348 640 }
7349
7350
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7351 {
7352
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7353 {
7354 new_return(16);
7355 }
7356 640 }
7357
7358 //down bomb rubble
7359
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7360 {
7361
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7362 {
7363 new_return(17);
7364 }
7365 640 }
7366
7367
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7368 {
7369
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7370 {
7371 new_return(18);
7372 }
7373 640 }
7374
7375 //left bomb rubble
7376
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7377 {
7378
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7379 {
7380 new_return(19);
7381 }
7382 960 }
7383
7384
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7385 {
7386
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7387 {
7388 new_return(20);
7389 }
7390 960 }
7391
7392 //right bomb rubble
7393
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7394 {
7395
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7396 {
7397 new_return(21);
7398 }
7399 960 }
7400
7401
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7402 {
7403
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7404 {
7405 new_return(22);
7406 }
7407 960 }
7408
7409 //walkthrough stuff
7410
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7411 {
7412
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7413 {
7414 new_return(23);
7415 }
7416 1280 }
7417
7418
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7419 {
7420
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7421 {
7422 new_return(24);
7423 }
7424 1280 }
7425
7426 //flags
7427
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7428 {
7429
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].flags[j],f))
7430 {
7431 new_return(25);
7432 }
7433 640 }
7434 320 }
7435
7436
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7437 {
7438 9 section_size=writesize;
7439 9 }
7440 18 }
7441
7442
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7443 {
7444 char ebuf[80];
7445 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7446 jwin_alert("Error: writedoorcombosets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7447 }
7448
7449 9 new_return(0);
7450 }
7451
7452 9216 int32_t write_one_dmap(PACKFILE* f, int index)
7453 {
7454 9216 DMaps[index].validate_subscreens();
7455
7456
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].map,f))
7457 {
7458 new_return(6);
7459 }
7460
7461
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].level,f))
7462 {
7463 new_return(7);
7464 }
7465
7466
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].xoff,f))
7467 {
7468 new_return(8);
7469 }
7470
7471
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].compass,f))
7472 {
7473 new_return(9);
7474 }
7475
7476
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].color,f))
7477 {
7478 new_return(10);
7479 }
7480
7481
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].midi,f))
7482 {
7483 new_return(11);
7484 }
7485
7486
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].cont,f))
7487 {
7488 new_return(12);
7489 }
7490
7491
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].type,f))
7492 {
7493 new_return(13);
7494 }
7495
7496
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t j=0; j<8; j++)
7497 {
7498
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(DMaps[index].grid[j],f))
7499 {
7500 new_return(14);
7501 }
7502 73728 }
7503
7504
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[index].name,sizeof(DMaps[0].name)-1,f))
7505 {
7506 new_return(15);
7507 }
7508
7509
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putwstr(DMaps[index].title,f))
7510 {
7511 new_return(16);
7512 }
7513
7514
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[index].intro,sizeof(DMaps[0].intro)-1,f))
7515 {
7516 new_return(17);
7517 }
7518
7519
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].minimap_tile[0],f))
7520 {
7521 new_return(18);
7522 }
7523
7524
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].minimap_cset[0],f))
7525 {
7526 new_return(19);
7527 }
7528
7529
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].minimap_tile[1],f))
7530 {
7531 new_return(20);
7532 }
7533
7534
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].minimap_cset[1],f))
7535 {
7536 new_return(21);
7537 }
7538
7539
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].largemap_tile[0],f))
7540 {
7541 new_return(22);
7542 }
7543
7544
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].largemap_cset[0],f))
7545 {
7546 new_return(23);
7547 }
7548
7549
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].largemap_tile[1],f))
7550 {
7551 new_return(24);
7552 }
7553
7554
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].largemap_cset[1],f))
7555 {
7556 new_return(25);
7557 }
7558
7559
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[index].tmusic,sizeof(DMaps[0].tmusic)-1,f))
7560 {
7561 new_return(26);
7562 }
7563
7564
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].tmusictrack,f))
7565 {
7566 new_return(25);
7567 }
7568
7569
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].active_subscreen,f))
7570 {
7571 new_return(26);
7572 }
7573
7574
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].passive_subscreen,f))
7575 {
7576 new_return(27);
7577 }
7578
7579 byte disabled[32];
7580 9216 memset(disabled,0,32);
7581
7582
2/2
✓ Branch 0 taken 2359296 times.
✓ Branch 1 taken 9216 times.
2368512 for(int32_t j=0; j<MAXITEMS; j++)
7583 {
7584
1/2
✓ Branch 0 taken 2359296 times.
✗ Branch 1 not taken.
2359296 if(DMaps[index].disableditems[j])
7585 {
7586 disabled[j/8] |= (1 << (j%8));
7587 }
7588 2359296 }
7589
7590
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(disabled,32,f))
7591 {
7592 new_return(28);
7593 }
7594
7595
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].flags,f))
7596 new_return(29);
7597
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].sideview,f))
7598 new_return(30);
7599
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].script,f))
7600 new_return(31);
7601
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7602
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[index].initD[q],f))
7603 new_return(32);
7604
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7605
2/2
✓ Branch 0 taken 4792320 times.
✓ Branch 1 taken 73728 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
7606
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if (!p_putc(DMaps[index].initD_label[q][w],f))
7607 73728 new_return(33);
7608
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].active_sub_script,f))
7609 new_return(34);
7610
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].passive_sub_script,f))
7611 new_return(35);
7612
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7613
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[index].sub_initD[q],f))
7614 new_return(36);
7615
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7616
2/2
✓ Branch 0 taken 4792320 times.
✓ Branch 1 taken 73728 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7617
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[index].sub_initD_label[q][w],f))
7618 73728 new_return(37);
7619
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].onmap_script,f))
7620 new_return(38);
7621
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7622
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[index].onmap_initD[q],f))
7623 new_return(39);
7624
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7625
2/2
✓ Branch 0 taken 4792320 times.
✓ Branch 1 taken 73728 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7626
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[index].onmap_initD_label[q][w],f))
7627 73728 new_return(40);
7628
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].mirrorDMap,f))
7629 new_return(41);
7630
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[index].tmusic_loop_start, f))
7631 new_return(42);
7632
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[index].tmusic_loop_end, f))
7633 new_return(43);
7634
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[index].tmusic_xfade_in, f))
7635 new_return(44);
7636
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[index].tmusic_xfade_out, f))
7637 new_return(45);
7638
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].overlay_subscreen, f))
7639 new_return(46);
7640
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[index].intro_string_id, f))
7641 new_return(47);
7642
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (DMaps[index].flags & dmfCUSTOM_GRAVITY)
7643 {
7644 if (!p_iputzf(DMaps[index].dmap_gravity, f))
7645 new_return(48);
7646 if (!p_iputzf(DMaps[index].dmap_terminal_v, f))
7647 new_return(49);
7648 }
7649
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].map_subscreen, f))
7650 new_return(50);
7651
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].floor, f))
7652 new_return(51);
7653 9216 return 0;
7654 }
7655 9 int32_t writedmaps(PACKFILE *f, word, word, word start_dmap, word max_dmaps)
7656 {
7657 9 word dmap_count=count_dmaps();
7658 9 dword section_id=ID_DMAPS;
7659 9 dword section_version=V_DMAPS;
7660 9 dword section_size=0;
7661
7662 //section id
7663
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7664 {
7665 new_return(1);
7666 }
7667
7668 //section version info
7669
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7670 {
7671 new_return(2);
7672 }
7673
7674
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7675 {
7676 new_return(3);
7677 }
7678
7679
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7680 {
7681 18 fake_pack_writing=(writecycle==0);
7682
7683 //section size
7684
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7685 {
7686 new_return(4);
7687 }
7688
7689 18 writesize=0;
7690
7691
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, max_dmaps);
7692
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7693
7694 //finally... section data
7695
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(dmap_count,f))
7696 {
7697 new_return(5);
7698 }
7699
7700
7701
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7702 {
7703
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if (auto ret = write_one_dmap(f, i))
7704 return ret;
7705 9216 }
7706
7707
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7708 {
7709 9 section_size=writesize;
7710 9 }
7711 18 }
7712
7713
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7714 {
7715 char ebuf[80];
7716 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7717 jwin_alert("Error: writedmaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7718 }
7719
7720 9 new_return(0);
7721 9 }
7722
7723 9 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7724 {
7725 //these are here to bypass compiler warnings about unused arguments
7726 9 Header=Header;
7727
7728 9 dword section_id=ID_COLORS;
7729 9 dword section_version=V_COLORS;
7730 9 dword section_size = 0;
7731
7732 //section id
7733
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7734 {
7735 new_return(1);
7736 }
7737
7738
7739 //section version info
7740
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7741 {
7742 new_return(2);
7743 }
7744
7745
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7746 {
7747 new_return(3);
7748 }
7749
7750
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7751 {
7752 18 fake_pack_writing=(writecycle==0);
7753
7754 //section size
7755
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7756 {
7757 new_return(4);
7758 }
7759
7760 18 writesize=0;
7761
7762
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.text,f))
7763 {
7764 new_return(5);
7765 }
7766
7767
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.caption,f))
7768 {
7769 new_return(6);
7770 }
7771
7772
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overw_bg,f))
7773 {
7774 new_return(7);
7775 }
7776
7777
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_bg,f))
7778 {
7779 new_return(8);
7780 }
7781
7782
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_fg,f))
7783 {
7784 new_return(9);
7785 }
7786
7787
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.cave_fg,f))
7788 {
7789 new_return(10);
7790 }
7791
7792
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_dk,f))
7793 {
7794 new_return(11);
7795 }
7796
7797
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_goal,f))
7798 {
7799 new_return(12);
7800 }
7801
7802
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_lt,f))
7803 {
7804 new_return(13);
7805 }
7806
7807
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_dk,f))
7808 {
7809 new_return(14);
7810 }
7811
7812
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_bg,f))
7813 {
7814 new_return(15);
7815 }
7816
7817
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_color,f))
7818 {
7819 new_return(16);
7820 }
7821
7822
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.hero_dot,f))
7823 {
7824 new_return(17);
7825 }
7826
7827
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_bg,f))
7828 {
7829 new_return(18);
7830 }
7831
7832
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_fg,f))
7833 {
7834 new_return(19);
7835 }
7836
7837
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triforce_cset,f))
7838 {
7839 new_return(20);
7840 }
7841
7842
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_cset,f))
7843 {
7844 new_return(21);
7845 }
7846
7847
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overworld_map_cset,f))
7848 {
7849 new_return(22);
7850 }
7851
7852
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
7853 {
7854 new_return(23);
7855 }
7856
7857
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.blueframe_cset,f))
7858 {
7859 new_return(24);
7860 }
7861
7862
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.HCpieces_cset,f))
7863 {
7864 new_return(31);
7865 }
7866
7867
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_shadow,f))
7868 {
7869 new_return(32);
7870 }
7871
7872
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.msgtext,f))
7873 {
7874 new_return(33);
7875 }
7876
7877
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triforce_tile,f))
7878 {
7879 new_return(34);
7880 }
7881
7882
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triframe_tile,f))
7883 {
7884 new_return(35);
7885 }
7886
7887
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
7888 {
7889 new_return(36);
7890 }
7891
7892
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
7893 {
7894 new_return(37);
7895 }
7896
7897
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.blueframe_tile,f))
7898 {
7899 new_return(38);
7900 }
7901
7902
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
7903 {
7904 new_return(39);
7905 }
7906
7907
7908
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7909 {
7910 9 section_size=writesize;
7911 9 }
7912 18 }
7913
7914
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7915 {
7916 char ebuf[80];
7917 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7918 jwin_alert("Error: writemisccolors()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7919 }
7920
7921 9 new_return(0);
7922 }
7923
7924 9 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
7925 {
7926 //these are here to bypass compiler warnings about unused arguments
7927 9 Header=Header;
7928
7929 9 dword section_id=ID_ICONS;
7930 9 dword section_version=V_ICONS;
7931 9 dword section_size = 0;
7932
7933 //section id
7934
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7935 {
7936 new_return(1);
7937 }
7938
7939 //section version info
7940
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7941 {
7942 new_return(2);
7943 }
7944
7945
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7946 {
7947 new_return(3);
7948 }
7949
7950
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7951 {
7952 18 fake_pack_writing=(writecycle==0);
7953
7954 //section size
7955
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7956 {
7957 new_return(4);
7958 }
7959
7960 18 writesize=0;
7961
7962
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
7963 {
7964
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(QMisc.icons[i],f))
7965 {
7966 new_return(5);
7967 }
7968 72 }
7969
7970
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7971 {
7972 9 section_size=writesize;
7973 9 }
7974 18 }
7975
7976
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7977 {
7978 char ebuf[80];
7979 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7980 jwin_alert("Error: writegameicons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7981 }
7982
7983 9 new_return(0);
7984 }
7985
7986 9 int32_t writemisc(PACKFILE *f, zquestheader *Header)
7987 {
7988 //these are here to bypass compiler warnings about unused arguments
7989 9 Header=Header;
7990
7991 9 dword section_id=ID_MISC;
7992 9 dword section_version=V_MISC;
7993 9 word shops=count_shops(&QMisc);
7994 9 word infos=count_infos(&QMisc);
7995 9 word warprings=count_warprings(&QMisc);
7996 9 word triforces=8;
7997 9 dword section_size = 0;
7998
7999 //section id
8000
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8001 {
8002 new_return(1);
8003 }
8004
8005
8006 //section version info
8007
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8008 {
8009 new_return(2);
8010 }
8011
8012
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8013 {
8014 new_return(3);
8015 }
8016
8017
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8018 {
8019 18 fake_pack_writing=(writecycle==0);
8020
8021 //section size
8022
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8023 {
8024 new_return(4);
8025 }
8026
8027 18 writesize=0;
8028
8029 //shops
8030
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(shops,f))
8031 {
8032 new_return(5);
8033 }
8034
8035
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8036 {
8037
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
8038 {
8039 new_return(6);
8040 }
8041
8042
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8043 {
8044
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].item[j],f))
8045 {
8046 new_return(7);
8047 }
8048 480 }
8049
8050
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8051 {
8052
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].price[j],f))
8053 {
8054 new_return(8);
8055 }
8056 480 }
8057
8058
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8059 {
8060
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8061 {
8062 new_return(9);
8063 }
8064 480 }
8065 160 }
8066
8067 //infos
8068
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(infos,f))
8069 {
8070 new_return(10);
8071 }
8072
8073
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<infos; i++)
8074 {
8075
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8076 {
8077 new_return(11);
8078 }
8079
8080
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8081 {
8082
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].str[j],f))
8083 {
8084 new_return(12);
8085 }
8086 480 }
8087
8088
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8089 {
8090
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].price[j],f))
8091 {
8092 new_return(13);
8093 }
8094 480 }
8095 160 }
8096
8097 //warp rings
8098
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(warprings,f))
8099 {
8100 new_return(14);
8101 }
8102
8103
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 18 times.
226 for(int32_t i=0; i<warprings; i++)
8104 {
8105
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8106 {
8107
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8108 {
8109 new_return(15);
8110 }
8111 1872 }
8112
8113
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8114 {
8115
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_putc(QMisc.warp[i].scr[j],f))
8116 {
8117 new_return(16);
8118 }
8119 1872 }
8120
8121
1/2
✓ Branch 0 taken 208 times.
✗ Branch 1 not taken.
208 if(!p_putc(QMisc.warp[i].size,f))
8122 {
8123 new_return(17);
8124 }
8125 208 }
8126
8127 //triforce pieces
8128
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for(int32_t i=0; i<triforces; i++)
8129 {
8130
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.triforce[i],f))
8131 {
8132 new_return(18);
8133 }
8134 144 }
8135
8136 //end string
8137
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(QMisc.endstring,f))
8138 {
8139 new_return(19);
8140 }
8141
8142 //V_MISC >= 8
8143
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8144 {
8145
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 480 times.
640 for(int32_t j=0; j<3; j++)
8146 {
8147
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].str[j],f))
8148 {
8149 new_return(20);
8150 }
8151 480 }
8152 160 }
8153 //V_MISC >= 9
8154
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8155 {
8156
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_iputl(QMisc.questmisc[q],f))
8157 new_return(21);
8158 576 }
8159
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8160 {
8161
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 576 times.
74304 for ( int32_t j = 0; j < 128; j++ )
8162
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(0,f))
8163 new_return(22);
8164 576 }
8165 //V_MISC >= 11
8166
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8167 new_return(23);
8168
8169 //V_MISC >= 12
8170
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sprMAX; ++q)
8171 {
8172
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.sprites[q],f))
8173 new_return(24);
8174 4608 }
8175
8176 //V_MISC >= 13
8177
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 18 times.
1170 for(size_t q = 0; q < 64; ++q)
8178 {
8179 1152 bottletype* bt = &(QMisc.bottle_types[q]);
8180
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!pfwrite(bt->name, 32, f))
8181 new_return(25);
8182
2/2
✓ Branch 0 taken 3456 times.
✓ Branch 1 taken 1152 times.
4608 for(size_t j = 0; j < 3; ++j)
8183 {
8184
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_putc(bt->counter[j], f))
8185 new_return(25);
8186
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_iputw(bt->amount[j], f))
8187 new_return(25);
8188 3456 }
8189
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->flags, f))
8190 new_return(25);
8191
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->next_type, f))
8192 new_return(25);
8193 1152 }
8194
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(size_t q = 0; q < 256; ++q)
8195 {
8196 4608 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8197
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!pfwrite(bst->name, 32, f))
8198 new_return(26);
8199
2/2
✓ Branch 0 taken 13824 times.
✓ Branch 1 taken 4608 times.
18432 for(size_t j = 0; j < 3; ++j)
8200 {
8201
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->fill[j], f))
8202 new_return(26);
8203
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->comb[j], f))
8204 new_return(26);
8205
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->cset[j], f))
8206 new_return(26);
8207
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->price[j], f))
8208 new_return(26);
8209
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13824 times.
13824 if (!p_iputw(bst->str[j], f))
8210 new_return(26);
8211 13824 }
8212 4608 }
8213
8214 //V_MISC >= 14
8215
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sfxMAX; ++q)
8216 {
8217
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.miscsfx[q],f))
8218 new_return(27);
8219 4608 }
8220
8221 //V_MISC >= 17
8222 18 byte save_menu_count = 0;
8223
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(size_t q = 0; q < NUM_SAVE_MENUS; ++q)
8224
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if (!QMisc.save_menus[q].is_empty())
8225 save_menu_count = q+1;
8226
8227
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(save_menu_count, f))
8228 new_return(28);
8229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(size_t q = 0; q < save_menu_count; ++q)
8230 {
8231 SaveMenu const& menu = QMisc.save_menus[q];
8232
8233 byte empty = menu.is_empty() ? 1 : 0;
8234
8235 if (!p_putc(empty, f))
8236 new_return(29);
8237 if (empty) continue;
8238
8239 if (!p_putcstr(menu.name, f))
8240 new_return(30);
8241
8242 if (!p_iputw(menu.flags, f))
8243 new_return(31);
8244
8245 if (!p_iputl(menu.cursor_tile, f))
8246 new_return(32);
8247
8248 if (!p_putc(menu.cursor_cset, f))
8249 new_return(33);
8250
8251 if (!p_putc(menu.cursor_sfx, f))
8252 new_return(34);
8253
8254 if (!p_putc(menu.choose_sfx, f))
8255 new_return(35);
8256
8257 if (!p_putc(menu.bg_color, f))
8258 new_return(36);
8259
8260 if (!p_putc(menu.hspace, f))
8261 new_return(37);
8262
8263 if (!p_putc(menu.vspace, f))
8264 new_return(38);
8265
8266 if (!p_putc(menu.opt_x, f))
8267 new_return(39);
8268
8269 if (!p_putc(menu.opt_y, f))
8270 new_return(40);
8271
8272 if (!p_putc(menu.text_align, f))
8273 new_return(41);
8274
8275 if (!p_putc(menu.textbox_align, f))
8276 new_return(42);
8277
8278 if (!p_iputw(menu.close_frames, f))
8279 new_return(43);
8280
8281 if (!p_putc(menu.close_flash_rate, f))
8282 new_return(44);
8283
8284 if (!p_iputw(menu.midi, f))
8285 new_return(45);
8286
8287 if (!p_iputl(menu.bg_tile, f))
8288 new_return(46);
8289
8290 if (!p_putc(menu.bg_cset, f))
8291 new_return(47);
8292
8293 if (!p_putc(menu.bg_tw, f))
8294 new_return(48);
8295
8296 if (!p_putc(menu.bg_th, f))
8297 new_return(49);
8298
8299 byte opt_count = zc_min(menu.options.size(), MAX_SAVEMENU_OPTIONS);
8300 if (!p_putc(opt_count, f))
8301 new_return(50);
8302
8303 for (size_t q = 0; q < opt_count; ++q)
8304 {
8305 SaveMenuOption const& opt = menu.options[q];
8306
8307 if (!p_putcstr(opt.text, f))
8308 new_return(51);
8309
8310 if (!p_iputw(opt.flags, f))
8311 new_return(52);
8312
8313 if (!p_putc(opt.color, f))
8314 new_return(53);
8315
8316 if (!p_putc(opt.picked_color, f))
8317 new_return(54);
8318
8319 if (!p_iputl(opt.font, f))
8320 new_return(55);
8321
8322 if (!p_iputw(opt.gen_script, f))
8323 new_return(56);
8324 }
8325 }
8326
8327
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(QMisc.savemenu_game_over, f))
8328 new_return(57);
8329
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(QMisc.savemenu_f6, f))
8330 new_return(58);
8331
8332
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8333 {
8334 9 section_size=writesize;
8335 9 }
8336 18 }
8337
8338
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8339 {
8340 char ebuf[80];
8341 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8342 jwin_alert("Error: writemisc()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8343 }
8344
8345 9 new_return(0);
8346 }
8347
8348 9 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8349 {
8350 //these are here to bypass compiler warnings about unused arguments
8351 9 Header=Header;
8352
8353 9 dword section_id=ID_ITEMS;
8354 9 dword section_version=V_ITEMS;
8355 // dword section_size=0;
8356 9 dword section_size = 0;
8357
8358 //section id
8359
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8360 {
8361 new_return(1);
8362 }
8363
8364 //section version info
8365
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8366 {
8367 new_return(2);
8368 }
8369
8370
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
8371 {
8372 new_return(3);
8373 }
8374
8375
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8376 {
8377 18 fake_pack_writing=(writecycle==0);
8378
8379 //section size
8380
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8381 {
8382 new_return(4);
8383 }
8384
8385 18 writesize=0;
8386
8387 //finally... section data
8388
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXITEMS,f))
8389 {
8390 new_return(5);
8391 }
8392
8393
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8394 {
8395
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite(item_string[i], 64, f))
8396 {
8397 new_return(5);
8398 }
8399 4608 }
8400
8401
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8402 {
8403
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tile,f))
8404 {
8405 new_return(6);
8406 }
8407
8408
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].misc_flags,f))
8409 {
8410 new_return(7);
8411 }
8412
8413
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].csets,f))
8414 {
8415 new_return(8);
8416 }
8417
8418
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].frames,f))
8419 {
8420 new_return(9);
8421 }
8422
8423
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].speed,f))
8424 {
8425 new_return(10);
8426 }
8427
8428
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].delay,f))
8429 {
8430 new_return(11);
8431 }
8432
8433
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].ltm,f))
8434 {
8435 new_return(12);
8436 }
8437
8438
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].type,f))
8439 {
8440 new_return(13);
8441 }
8442
8443
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].level,f))
8444 {
8445 new_return(14);
8446 }
8447
8448
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].power,f))
8449 {
8450 new_return(14);
8451 }
8452
8453
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].flags,f))
8454 {
8455 new_return(15);
8456 }
8457
8458
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].script,f))
8459 {
8460 new_return(16);
8461 }
8462
8463
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].count,f))
8464 {
8465 new_return(17);
8466 }
8467
8468
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].amount,f))
8469 {
8470 new_return(18);
8471 }
8472
8473
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].collect_script,f))
8474 {
8475 new_return(19);
8476 }
8477
8478
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].setmax,f))
8479 {
8480 new_return(21);
8481 }
8482
8483
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].max,f))
8484 {
8485 new_return(22);
8486 }
8487
8488
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].playsound,f))
8489 {
8490 new_return(23);
8491 }
8492
8493
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for(int32_t j=0; j<8; j++)
8494 {
8495
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].initiald[j],f))
8496 {
8497 new_return(24);
8498 }
8499 36864 }
8500
8501
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(int32_t j=0; j<2; j++)
8502 {
8503
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8504 {
8505 new_return(25);
8506 }
8507 9216 }
8508
8509
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn,f))
8510 {
8511 new_return(26);
8512 }
8513
8514
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn2,f))
8515 {
8516 new_return(27);
8517 }
8518
8519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn3,f))
8520 {
8521 new_return(28);
8522 }
8523
8524
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn4,f))
8525 {
8526 new_return(29);
8527 }
8528
8529
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn5,f))
8530 {
8531 new_return(30);
8532 }
8533
8534
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn6,f))
8535 {
8536 new_return(31);
8537 }
8538
8539
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn7,f))
8540 {
8541 new_return(32);
8542 }
8543
8544
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn8,f))
8545 {
8546 new_return(33);
8547 }
8548
8549
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn9,f))
8550 {
8551 new_return(34);
8552 }
8553
8554
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn10,f))
8555 {
8556 new_return(35);
8557 }
8558
8559
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8560 {
8561 new_return(36);
8562 }
8563
8564
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc1,f))
8565 {
8566 new_return(37);
8567 }
8568
8569
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc2,f))
8570 {
8571 new_return(38);
8572 }
8573
8574
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8575 {
8576
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8577 {
8578 new_return(39);
8579 }
8580 9216 }
8581
8582
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc3,f))
8583 {
8584 new_return(40);
8585 }
8586
8587
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc4,f))
8588 {
8589 new_return(41);
8590 }
8591
8592
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc5,f))
8593 {
8594 new_return(42);
8595 }
8596
8597
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc6,f))
8598 {
8599 new_return(43);
8600 }
8601
8602
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc7,f))
8603 {
8604 new_return(44);
8605 }
8606
8607
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc8,f))
8608 {
8609 new_return(45);
8610 }
8611
8612
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc9,f))
8613 {
8614 new_return(46);
8615 }
8616
8617
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc10,f))
8618 {
8619 new_return(47);
8620 }
8621
8622
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound,f))
8623 {
8624 new_return(48);
8625 }
8626
8627
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound2,f))
8628 {
8629 new_return(48);
8630 }
8631
8632 //New itemdata vars -Z
8633 //! version 27
8634
8635
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weaprange,f))
8636 {
8637 new_return(51);
8638 }
8639
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weapduration,f))
8640 {
8641 new_return(52);
8642 }
8643
2/2
✓ Branch 0 taken 46080 times.
✓ Branch 1 taken 4608 times.
50688 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8644
1/2
✓ Branch 0 taken 46080 times.
✗ Branch 1 not taken.
46080 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8645 {
8646 new_return(53);
8647 }
8648 46080 }
8649 //version 28
8650
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].duplicates,f))
8651 {
8652 new_return(54);
8653 }
8654
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8655 {
8656
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8657 {
8658 new_return(56);
8659 }
8660 9216 }
8661
8662
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].drawlayer,f))
8663 {
8664 new_return(57);
8665 }
8666
8667
8668
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxofs,f))
8669 {
8670 new_return(58);
8671 }
8672
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hyofs,f))
8673 {
8674 new_return(59);
8675 }
8676
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxsz,f))
8677 {
8678 new_return(60);
8679 }
8680
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hysz,f))
8681 {
8682 new_return(61);
8683 }
8684
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hzsz,f))
8685 {
8686 new_return(62);
8687 }
8688
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].xofs,f))
8689 {
8690 new_return(63);
8691 }
8692
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].yofs,f))
8693 {
8694 new_return(64);
8695 }
8696
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8697 {
8698 new_return(73);
8699 }
8700
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8701 {
8702
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8703 {
8704 new_return(74);
8705 }
8706 9216 }
8707
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8708 {
8709 new_return(75);
8710 }
8711
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tilew,f))
8712 {
8713 new_return(76);
8714 }
8715
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tileh,f))
8716 {
8717 new_return(77);
8718 }
8719
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].pickup,f))
8720 {
8721 new_return(81);
8722 }
8723
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pstring,f))
8724 {
8725 new_return(82);
8726 }
8727
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8728 {
8729 new_return(83);
8730 }
8731
8732
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8733 {
8734
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8735 {
8736 new_return(84);
8737 }
8738 9216 }
8739
8740 //InitD[] labels
8741
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for ( int32_t q = 0; q < 8; q++ )
8742 {
8743
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8744 {
8745
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8746 {
8747 new_return(85);
8748 }
8749 2396160 }
8750
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8751 {
8752
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8753 {
8754 new_return(87);
8755 }
8756 2396160 }
8757
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8758 {
8759 new_return(88);
8760 }
8761 36864 }
8762
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8763 {
8764
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8765 {
8766 new_return(89);
8767 }
8768
8769 9216 }
8770
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].sprite_script,f))
8771 {
8772 new_return(90);
8773 }
8774
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].pickupflag,f))
8775 {
8776 new_return(91);
8777 }
8778
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 std::string dispname(itemsbuf[i].display_name);
8779
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(!p_putcstr(dispname,f))
8780 new_return(92);
8781
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litems, f))
8782 new_return(95);
8783
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litem_level, f))
8784 new_return(96);
8785
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if (!p_iputl(itemsbuf[i].moveflags, f))
8786 new_return(97);
8787
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(auto ret = write_weap_data(itemsbuf[i].weap_data, f))
8788 return ret;
8789
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if (!p_iputl(itemsbuf[i].cooldown, f))
8790 new_return(98);
8791
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
4608 }
8792
8793
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8794 {
8795 9 section_size=writesize;
8796 9 }
8797 18 }
8798
8799
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8800 {
8801 char ebuf[80];
8802 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8803 jwin_alert("Error: writeitems()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8804 }
8805
8806 9 new_return(0);
8807 9 }
8808
8809 9 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8810 {
8811 //these are here to bypass compiler warnings about unused arguments
8812 9 Header=Header;
8813
8814 9 dword section_id=ID_WEAPONS;
8815 9 dword section_version=V_WEAPONS;
8816 9 dword section_size = 0;
8817
8818 //section id
8819
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8820 {
8821 new_return(1);
8822 }
8823
8824 //section version info
8825
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8826 {
8827 new_return(2);
8828 }
8829
8830
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8831 {
8832 new_return(3);
8833 }
8834
8835
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8836 {
8837 18 fake_pack_writing=(writecycle==0);
8838
8839 //section size
8840
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8841 {
8842 new_return(4);
8843 }
8844
8845 18 writesize=0;
8846
8847 //finally... section data
8848
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXWPNS,f))
8849 {
8850 new_return(5);
8851 }
8852
8853
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8854 {
8855
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite((char *)weapon_string[i], 64, f))
8856 {
8857 new_return(5);
8858 }
8859 4608 }
8860
8861
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8862 {
8863
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].misc,f))
8864 {
8865 new_return(7);
8866 }
8867
8868
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].csets,f))
8869 {
8870 new_return(8);
8871 }
8872
8873
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].frames,f))
8874 {
8875 new_return(9);
8876 }
8877
8878
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].speed,f))
8879 {
8880 new_return(10);
8881 }
8882
8883
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].type,f))
8884 {
8885 new_return(11);
8886 }
8887
8888
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(wpnsbuf[i].script,f))
8889 {
8890 new_return(12);
8891 }
8892
8893
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(wpnsbuf[i].tile,f))
8894 {
8895 new_return(12);
8896 }
8897 4608 }
8898
8899
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8900 {
8901 9 section_size=writesize;
8902 9 }
8903 18 }
8904
8905
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8906 {
8907 char ebuf[80];
8908 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8909 jwin_alert("Error: writeweapons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8910 }
8911
8912 9 new_return(0);
8913 }
8914
8915 12784 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
8916 {
8917
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12784 times.
12784 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
8918 return qe_invalid;
8919
8920 12784 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
8921 12784 bool is_0x80_screen = j >= 0x80;
8922
8923
1/2
✓ Branch 0 taken 12784 times.
✗ Branch 1 not taken.
12784 if(!p_putc(screen.valid,f))
8924 return qe_invalid;
8925
2/2
✓ Branch 0 taken 8380 times.
✓ Branch 1 taken 4404 times.
12784 if(!(screen.valid & mVALID))
8926 4404 return qe_OK;
8927 //Calculate what needs writing
8928 8380 uint32_t scr_has_flags = 0;
8929
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8378 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8380 if(screen.guytile || screen.guy || screen.roomflags || screen.str
8930
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
8931 8380 scr_has_flags |= SCRHAS_ROOMDATA;
8932
7/8
✓ Branch 0 taken 7946 times.
✓ Branch 1 taken 434 times.
✓ Branch 2 taken 192 times.
✓ Branch 3 taken 7754 times.
✓ Branch 4 taken 180 times.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 180 times.
8380 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
8933 446 scr_has_flags |= SCRHAS_ITEM;
8934
3/4
✓ Branch 0 taken 8352 times.
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8352 times.
8380 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
8935 28 scr_has_flags |= SCRHAS_TWARP;
8936
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 32882 times.
41058 else for(auto q = 0; q < 4; ++q)
8937 {
8938
1/2
✓ Branch 0 taken 32706 times.
✗ Branch 1 not taken.
65588 if(screen.tilewarptype[q]
8939
2/2
✓ Branch 0 taken 32708 times.
✓ Branch 1 taken 174 times.
32882 || screen.tilewarpdmap[q]
8940
2/2
✓ Branch 0 taken 32706 times.
✓ Branch 1 taken 2 times.
32708 || screen.tilewarpscr[q])
8941 {
8942 176 scr_has_flags |= SCRHAS_TWARP;
8943 176 break;
8944 }
8945 32706 }
8946
3/4
✓ Branch 0 taken 8376 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8344 times.
8380 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
8947
2/2
✓ Branch 0 taken 8344 times.
✓ Branch 1 taken 32 times.
8376 || screen.sidewarpoverlayflags)
8948 36 scr_has_flags |= SCRHAS_SWARP;
8949
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 20568 times.
24642 else for(auto q = 0; q < 4; ++q)
8950 {
8951
2/2
✓ Branch 0 taken 16298 times.
✓ Branch 1 taken 12 times.
36878 if(screen.sidewarptype[q] != wtSCROLL
8952
2/2
✓ Branch 0 taken 16436 times.
✓ Branch 1 taken 4132 times.
20568 || screen.sidewarpdmap[q]
8953
2/2
✓ Branch 0 taken 16310 times.
✓ Branch 1 taken 126 times.
16436 || screen.sidewarpscr[q])
8954 {
8955 4270 scr_has_flags |= SCRHAS_SWARP;
8956 4270 break;
8957 }
8958 16298 }
8959
3/4
✓ Branch 0 taken 8336 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8336 times.
8380 if(screen.warparrivalx || screen.warparrivaly)
8960 44 scr_has_flags |= SCRHAS_WARPRET;
8961
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 30992 times.
38544 else for(auto q = 0; q < 4; ++q)
8962 {
8963
4/4
✓ Branch 0 taken 30210 times.
✓ Branch 1 taken 782 times.
✓ Branch 2 taken 30208 times.
✓ Branch 3 taken 2 times.
30992 if(screen.warpreturnx[q] || screen.warpreturny[q])
8964 {
8965 784 scr_has_flags |= SCRHAS_WARPRET;
8966 784 break;
8967 }
8968 30208 }
8969
8970
2/4
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8380 times.
8380 if(screen.hidelayers || screen.hidescriptlayers)
8971 scr_has_flags |= SCRHAS_LAYERS;
8972
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 45498 times.
52912 else for(auto q = 0; q < 6; ++q)
8973 {
8974
4/4
✓ Branch 0 taken 44552 times.
✓ Branch 1 taken 946 times.
✓ Branch 2 taken 44532 times.
✓ Branch 3 taken 20 times.
45498 if(screen.layermap[q] || screen.layerscreen[q]
8975
1/2
✓ Branch 0 taken 44552 times.
✗ Branch 1 not taken.
44552 || screen.layeropacity[q]!=255)
8976 {
8977 966 scr_has_flags |= SCRHAS_LAYERS;
8978 966 break;
8979 }
8980 44532 }
8981
8982
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8370 times.
8380 if(screen.exitdir)
8983 10 scr_has_flags |= SCRHAS_MAZE;
8984
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8370 times.
8370 else if(screen.maze_transition_wipe)
8985 scr_has_flags |= SCRHAS_MAZE;
8986
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 33480 times.
41850 else for(auto q = 0; q < 4; ++q)
8987 {
8988
1/2
✓ Branch 0 taken 33480 times.
✗ Branch 1 not taken.
33480 if(screen.path[q])
8989 {
8990 scr_has_flags |= SCRHAS_MAZE;
8991 break;
8992 }
8993 33480 }
8994
8995
4/4
✓ Branch 0 taken 8146 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 322 times.
✓ Branch 3 taken 5412 times.
14114 if(screen.door_combo_set || screen.stairx
8996
3/4
✓ Branch 0 taken 8118 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 8118 times.
✗ Branch 3 not taken.
8146 || screen.stairy || screen.undercombo
8997
2/2
✓ Branch 0 taken 5734 times.
✓ Branch 1 taken 2384 times.
8118 || screen.undercset)
8998 2968 scr_has_flags |= SCRHAS_D_S_U;
8999
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 6012 times.
6212 else for(auto q = 0; q < 4; ++q)
9000 {
9001
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 5212 times.
6012 if(screen.door[q] != dNONE)
9002 {
9003 5212 scr_has_flags |= SCRHAS_D_S_U;
9004 5212 break;
9005 }
9006 800 }
9007
9008
2/2
✓ Branch 0 taken 8076 times.
✓ Branch 1 taken 304 times.
15600 if(screen.flags || screen.flags2
9009
4/4
✓ Branch 0 taken 7830 times.
✓ Branch 1 taken 246 times.
✓ Branch 2 taken 7698 times.
✓ Branch 3 taken 132 times.
8076 || screen.flags3 || screen.flags4
9010
4/4
✓ Branch 0 taken 7684 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 7662 times.
✓ Branch 3 taken 22 times.
7698 || screen.flags5 || screen.flags6
9011
4/4
✓ Branch 0 taken 7448 times.
✓ Branch 1 taken 214 times.
✓ Branch 2 taken 7220 times.
✓ Branch 3 taken 228 times.
7662 || screen.flags7 || screen.flags8
9012
2/4
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7220 times.
✗ Branch 3 not taken.
7220 || screen.flags9 || screen.flags10
9013
1/2
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
7220 || screen.flags11)
9014 8380 scr_has_flags |= SCRHAS_FLAGS;
9015
9016
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 8322 times.
8380 if(screen.pattern)
9017 58 scr_has_flags |= SCRHAS_ENEMY;
9018
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 74100 times.
81408 else for(auto q = 0; q < 10; ++q)
9019 {
9020
2/2
✓ Branch 0 taken 73086 times.
✓ Branch 1 taken 1014 times.
74100 if(screen.enemy[q])
9021 {
9022 1014 scr_has_flags |= SCRHAS_ENEMY;
9023 1014 break;
9024 }
9025 73086 }
9026
9027
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8380 if(screen.noreset != mDEF_NORESET || screen.nocarry != mDEF_NOCARRYOVER
9028 || screen.nextmap || screen.nextscr || screen.exstate_reset || screen.exstate_carry)
9029 8380 scr_has_flags |= SCRHAS_CARRY;
9030
9031
3/4
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8358 times.
8380 if(screen.script || screen.preloadscript)
9032 22 scr_has_flags |= SCRHAS_SCRIPT;
9033
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 66864 times.
75222 else for(auto q = 0; q < 8; ++q)
9034 {
9035
1/2
✓ Branch 0 taken 66864 times.
✗ Branch 1 not taken.
66864 if(screen.screeninitd[q])
9036 {
9037 scr_has_flags |= SCRHAS_SCRIPT;
9038 break;
9039 }
9040 66864 }
9041
9042
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 683992 times.
689296 for(auto q = 0; q < 128; ++q)
9043 {
9044
1/2
✓ Branch 0 taken 680916 times.
✗ Branch 1 not taken.
1364908 if(screen.secretcombo[q]
9045
2/2
✓ Branch 0 taken 680922 times.
✓ Branch 1 taken 3070 times.
683992 || screen.secretcset[q]
9046
2/2
✓ Branch 0 taken 680916 times.
✓ Branch 1 taken 6 times.
680922 || screen.secretflag[q])
9047 {
9048 3076 scr_has_flags |= SCRHAS_SECRETS;
9049 3076 break;
9050 }
9051 680916 }
9052
9053
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 573892 times.
576912 for(auto q = 0; q < 176; ++q)
9054 {
9055
4/4
✓ Branch 0 taken 568780 times.
✓ Branch 1 taken 5112 times.
✓ Branch 2 taken 568532 times.
✓ Branch 3 taken 12 times.
573892 if(screen.data[q] || screen.cset[q]
9056
2/2
✓ Branch 0 taken 568544 times.
✓ Branch 1 taken 236 times.
568780 || screen.sflag[q])
9057 {
9058 5360 scr_has_flags |= SCRHAS_COMBOFLAG;
9059 5360 break;
9060 }
9061 568532 }
9062
9063
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 2236 times.
8380 if(screen.color || screen.csensitive != 1
9064
3/4
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6110 times.
✓ Branch 3 taken 34 times.
6144 || screen.oceansfx || screen.bosssfx
9065
2/4
✓ Branch 0 taken 6110 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6110 times.
6110 || screen.secretsfx || screen.holdupsfx
9066 || screen.timedwarptics || screen.screen_midi != -1
9067 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9068 8380 scr_has_flags |= SCRHAS_MISC;
9069
9070
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(scr_has_flags,f))
9071 return qe_invalid;
9072
9073 //Write stuff
9074
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_ROOMDATA)
9075 {
9076
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guy,f))
9077 return qe_invalid;
9078
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.guytile,f))
9079 return qe_invalid;
9080
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guycs,f))
9081 return qe_invalid;
9082
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.roomflags,f))
9083 return qe_invalid;
9084
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.str,f))
9085 return qe_invalid;
9086
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.room,f))
9087 return qe_invalid;
9088
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.catchall,f))
9089 return qe_invalid;
9090 8380 }
9091
2/2
✓ Branch 0 taken 7934 times.
✓ Branch 1 taken 446 times.
8380 if(scr_has_flags & SCRHAS_ITEM)
9092 {
9093
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.item,f))
9094 return qe_invalid;
9095
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.hasitem,f))
9096 return qe_invalid;
9097
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemx,f))
9098 return qe_invalid;
9099
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemy,f))
9100 return qe_invalid;
9101 446 }
9102
2/2
✓ Branch 0 taken 4006 times.
✓ Branch 1 taken 4374 times.
8380 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9103 {
9104
1/2
✓ Branch 0 taken 4374 times.
✗ Branch 1 not taken.
4374 if(!p_iputw(screen.warpreturnc,f))
9105 return qe_invalid;
9106 4374 }
9107
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 204 times.
8380 if(scr_has_flags & SCRHAS_TWARP)
9108 {
9109
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9110 {
9111
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarptype[k],f))
9112 return qe_invalid;
9113 816 }
9114
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9115 {
9116
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_iputw(screen.tilewarpdmap[k],f))
9117 return qe_invalid;
9118 816 }
9119
9120
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9121 {
9122
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarpscr[k],f))
9123 return qe_invalid;
9124 816 }
9125
9126
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 if(!p_putc(screen.tilewarpoverlayflags,f))
9127 return qe_invalid;
9128 204 }
9129
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 4306 times.
8380 if(scr_has_flags & SCRHAS_SWARP)
9130 {
9131
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9132 {
9133
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarptype[k],f))
9134 return qe_invalid;
9135 17224 }
9136
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9137 {
9138
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_iputw(screen.sidewarpdmap[k],f))
9139 return qe_invalid;
9140 17224 }
9141
9142
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9143 {
9144
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarpscr[k],f))
9145 return qe_invalid;
9146 17224 }
9147
9148
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpoverlayflags,f))
9149 return qe_invalid;
9150
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpindex,f))
9151 return qe_invalid;
9152 4306 }
9153
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 828 times.
8380 if(scr_has_flags & SCRHAS_WARPRET)
9154 {
9155
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9156 {
9157
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturnx[k],f))
9158 return qe_invalid;
9159 3312 }
9160
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9161 {
9162
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturny[k],f))
9163 return qe_invalid;
9164 3312 }
9165
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivalx,f))
9166 return qe_invalid;
9167
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivaly,f))
9168 return qe_invalid;
9169 828 }
9170
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 966 times.
8380 if(scr_has_flags & SCRHAS_LAYERS)
9171 {
9172
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9173 {
9174
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layermap[k],f))
9175 return qe_invalid;
9176 5796 }
9177
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9178 {
9179
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layerscreen[k],f))
9180 return qe_invalid;
9181 5796 }
9182
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9183 {
9184
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layeropacity[k],f))
9185 return qe_invalid;
9186 5796 }
9187
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidelayers,f))
9188 return qe_invalid;
9189
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidescriptlayers,f))
9190 return qe_invalid;
9191 966 }
9192
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 10 times.
8380 if(scr_has_flags & SCRHAS_MAZE)
9193 {
9194
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 10 times.
50 for(int32_t k=0; k<4; k++)
9195 {
9196
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!p_putc(screen.path[k],f))
9197 return qe_invalid;
9198 40 }
9199
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.exitdir,f))
9200 return qe_invalid;
9201
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.maze_transition_wipe,f))
9202 return qe_invalid;
9203 10 }
9204
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 8180 times.
8380 if(scr_has_flags & SCRHAS_D_S_U)
9205 {
9206
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.door_combo_set,f))
9207 return qe_invalid;
9208
2/2
✓ Branch 0 taken 32720 times.
✓ Branch 1 taken 8180 times.
40900 for(int32_t k=0; k<4; k++)
9209 {
9210
1/2
✓ Branch 0 taken 32720 times.
✗ Branch 1 not taken.
32720 if(!p_putc(screen.door[k],f))
9211 return qe_invalid;
9212 32720 }
9213
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairx,f))
9214 return qe_invalid;
9215
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairy,f))
9216 return qe_invalid;
9217
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.undercombo,f))
9218 return qe_invalid;
9219
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.undercset,f))
9220 return qe_invalid;
9221 8180 }
9222
2/2
✓ Branch 0 taken 7086 times.
✓ Branch 1 taken 1294 times.
8380 if(scr_has_flags & SCRHAS_FLAGS)
9223 {
9224
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags,f))
9225 return qe_invalid;
9226
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags2,f))
9227 return qe_invalid;
9228
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags3,f))
9229 return qe_invalid;
9230
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags4,f))
9231 return qe_invalid;
9232
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags5,f))
9233 return qe_invalid;
9234
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags6,f))
9235 return qe_invalid;
9236
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags7,f))
9237 return qe_invalid;
9238
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags8,f))
9239 return qe_invalid;
9240
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags9,f))
9241 return qe_invalid;
9242
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags10,f))
9243 return qe_invalid;
9244
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags11,f))
9245 return qe_invalid;
9246 1294 }
9247
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 1072 times.
8380 if(scr_has_flags & SCRHAS_ENEMY)
9248 {
9249
2/2
✓ Branch 0 taken 10720 times.
✓ Branch 1 taken 1072 times.
11792 for(int32_t k=0; k<10; k++)
9250 {
9251
1/2
✓ Branch 0 taken 10720 times.
✗ Branch 1 not taken.
10720 if(!p_iputw(screen.enemy[k],f))
9252 return qe_invalid;
9253 10720 }
9254
1/2
✓ Branch 0 taken 1072 times.
✗ Branch 1 not taken.
1072 if(!p_putc(screen.pattern,f))
9255 return qe_invalid;
9256 1072 }
9257
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_CARRY)
9258 {
9259
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.noreset,f))
9260 return qe_invalid;
9261
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.nocarry,f))
9262 return qe_invalid;
9263
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_reset,f))
9264 return qe_invalid;
9265
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_carry,f))
9266 return qe_invalid;
9267
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextmap,f))
9268 return qe_invalid;
9269
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextscr,f))
9270 return qe_invalid;
9271 8380 }
9272
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
8380 if(scr_has_flags & SCRHAS_SCRIPT)
9273 {
9274
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(screen.script,f))
9275 return qe_invalid;
9276
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_putc(screen.preloadscript,f))
9277 return qe_invalid;
9278
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 22 times.
198 for ( int32_t q = 0; q < 8; q++ )
9279 {
9280
1/2
✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
176 if(!p_iputl(screen.screeninitd[q],f))
9281 return qe_invalid;
9282 176 }
9283 22 }
9284
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 3076 times.
8380 if(scr_has_flags & SCRHAS_SECRETS)
9285 {
9286
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9287 {
9288
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_iputw(screen.secretcombo[k],f))
9289 return qe_invalid;
9290 393728 }
9291
9292
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9293 {
9294
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretcset[k],f))
9295 return qe_invalid;
9296 393728 }
9297
9298
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9299 {
9300
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretflag[k],f))
9301 return qe_invalid;
9302 393728 }
9303 3076 }
9304
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 5360 times.
8380 if(scr_has_flags & SCRHAS_COMBOFLAG)
9305 {
9306
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9307 {
9308
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_iputw(screen.data[k],f))
9309 return qe_invalid;
9310 943360 }
9311
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9312 {
9313
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.sflag[k],f))
9314 return qe_invalid;
9315 943360 }
9316
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9317 {
9318
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.cset[k],f))
9319 return qe_invalid;
9320 943360 }
9321 5360 }
9322
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_MISC)
9323 {
9324
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.color,f))
9325 return qe_invalid;
9326
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.csensitive,f))
9327 return qe_invalid;
9328
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.oceansfx,f))
9329 return qe_invalid;
9330
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.bosssfx,f))
9331 return qe_invalid;
9332
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.secretsfx,f))
9333 return qe_invalid;
9334
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.holdupsfx,f))
9335 return qe_invalid;
9336
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.timedwarptics,f))
9337 return qe_invalid;
9338
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.screen_midi,f))
9339 return qe_invalid;
9340
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_layer,f))
9341 return qe_invalid;
9342
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(!p_putc(screen.lens_show,f))
9343 return qe_invalid;
9344
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_hide,f))
9345 return qe_invalid;
9346 8380 }
9347
9348 8380 dword numffc = screen.numFFC();
9349
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(numffc,f))
9350 return qe_invalid;
9351
2/2
✓ Branch 0 taken 245678 times.
✓ Branch 1 taken 8380 times.
254058 for(int32_t k=0; k<numffc; ++k)
9352 {
9353 245678 ffcdata const& tempffc = screen.ffcs[k];
9354
9355
1/2
✓ Branch 0 taken 245678 times.
✗ Branch 1 not taken.
245678 if(!p_iputw(tempffc.data,f))
9356 return qe_invalid;
9357
9358
2/2
✓ Branch 0 taken 2314 times.
✓ Branch 1 taken 243364 times.
245678 if(!tempffc.data) //don't save the rest of the ffc
9359 243364 continue;
9360
9361
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.cset,f))
9362 return qe_invalid;
9363
9364
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.delay,f))
9365 return qe_invalid;
9366
9367
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.x,f))
9368 return qe_invalid;
9369
9370
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.y,f))
9371 return qe_invalid;
9372
9373
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vx,f))
9374 return qe_invalid;
9375
9376
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vy,f))
9377 return qe_invalid;
9378
9379
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ax,f))
9380 return qe_invalid;
9381
9382
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ay,f))
9383 return qe_invalid;
9384
9385
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.link,f))
9386 return qe_invalid;
9387
9388
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_width,f))
9389 return qe_invalid;
9390
9391
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_height,f))
9392 return qe_invalid;
9393
9394
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.txsz,f))
9395 return qe_invalid;
9396
9397
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.tysz,f))
9398 return qe_invalid;
9399
9400
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.flags,f))
9401 return qe_invalid;
9402
9403
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.script,f))
9404 return qe_invalid;
9405
9406
2/2
✓ Branch 0 taken 18512 times.
✓ Branch 1 taken 2314 times.
20826 for(auto q = 0; q < 8; ++q)
9407 {
9408
1/2
✓ Branch 0 taken 18512 times.
✗ Branch 1 not taken.
18512 if(!p_iputl(tempffc.initd[q],f))
9409 return qe_invalid;
9410 18512 }
9411
9412
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.layer,f))
9413 return qe_invalid;
9414 2314 }
9415
9416
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putlstr(screen.usr_notes, f))
9417 return qe_invalid;
9418
9419
2/2
✓ Branch 0 taken 8374 times.
✓ Branch 1 taken 6 times.
8380 if (screen.flags10 & fSCREEN_GRAVITY)
9420 {
9421
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_gravity, f))
9422 return qe_invalid;
9423
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_terminal_v, f))
9424 return qe_invalid;
9425 6 }
9426
9427 8380 return qe_OK;
9428 12784 }
9429
9430 9 int32_t writemaps(PACKFILE *f, zquestheader *)
9431 {
9432 9 dword section_id=ID_MAPS;
9433 9 dword section_version=V_MAPS;
9434 9 dword section_size = 0;
9435
9436 //section id
9437
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9438 {
9439 new_return(1);
9440 }
9441
9442 //section version info
9443
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9444 {
9445 new_return(2);
9446 }
9447
9448
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
9449 {
9450 new_return(3);
9451 }
9452
9453
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9454 {
9455 18 fake_pack_writing=(writecycle==0);
9456
9457 //section size
9458
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9459 {
9460 new_return(4);
9461 }
9462
9463 18 writesize=0;
9464
9465
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(map_count,f))
9466 {
9467 new_return(5);
9468 }
9469 18 map_infos.resize(map_count);
9470
4/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 100 times.
✓ Branch 3 taken 18 times.
118 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9471 {
9472 100 byte valid = 0;
9473
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1282 times.
1288 for(int32_t j=0; j<MAPSCRS; j++)
9474 {
9475
1/2
✓ Branch 0 taken 1282 times.
✗ Branch 1 not taken.
1282 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9476 break;
9477 1282 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9478
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 1188 times.
1282 if (screen.is_valid())
9479 {
9480 94 valid = 1;
9481 94 break;
9482 }
9483 1188 }
9484
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 if(!p_putc(valid,f))
9485 {
9486 new_return(6);
9487 }
9488
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 6 times.
100 if(!valid) continue;
9489
9490 { //per-map info
9491 94 auto const& mapinf = map_infos[i];
9492
2/2
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 94 times.
658 for(int q = 0; q < 6; ++q)
9493 {
9494
1/2
✓ Branch 0 taken 564 times.
✗ Branch 1 not taken.
564 if(!p_iputw(mapinf.autolayers[q],f))
9495 new_return(7);
9496 564 }
9497
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 if(!p_iputw(mapinf.autopalette,f))
9498 new_return(9);
9499
9500
9501
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 94 times.
846 for(int32_t j=0; j<8; j++)
9502 {
9503
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 6016 times.
6768 for(int32_t k=0; k<8; k++)
9504 {
9505
1/2
✓ Branch 0 taken 6016 times.
✗ Branch 1 not taken.
6016 if(!p_putc(Regions[i].region_ids[j][k],f))
9506 {
9507 new_return(8);
9508 }
9509 6016 }
9510 752 }
9511 }
9512
9513
2/2
✓ Branch 0 taken 12784 times.
✓ Branch 1 taken 94 times.
12878 for(int32_t j=0; j<MAPSCRS; j++)
9514 12784 writemapscreen(f,i,j);
9515 94 }
9516
9517
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9518 {
9519 9 section_size=writesize;
9520 9 }
9521 18 }
9522
9523
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9524 {
9525 char ebuf[80];
9526 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9527 jwin_alert("Error: writemaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9528 }
9529
9530 9 new_return(0);
9531 }
9532
9533 460 int32_t writecombo_triggers_loop(PACKFILE *f, word section_version, combo_trigger const& tmp_trig)
9534 {
9535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putcstr(tmp_trig.label,f))
9536 return 22;
9537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.trigger_flags,f))
9538 return 22;
9539
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.triggerlevel,f))
9540 return 23;
9541
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggerbtn,f))
9542 return 34;
9543
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggeritem,f))
9544 return 35;
9545
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigtimer,f))
9546 return 36;
9547
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigsfx,f))
9548 return 37;
9549
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigchange,f))
9550 return 38;
9551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigprox,f))
9552 return 39;
9553
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigctr,f))
9554 return 40;
9555
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigctramnt,f))
9556 return 41;
9557
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triglbeam,f))
9558 return 42;
9559
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcschange,f))
9560 return 43;
9561
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnitem,f))
9562 return 44;
9563
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnenemy,f))
9564 return 45;
9565
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exstate,f))
9566 return 46;
9567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.spawnip,f))
9568 return 47;
9569
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcopycat,f))
9570 return 48;
9571
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcooldown,f))
9572 return 49;
9573
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_cid,f))
9574 return 50;
9575
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.prompt_cs,f))
9576 return 51;
9577
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_x,f))
9578 return 52;
9579
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_y,f))
9580 return 53;
9581
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_lstate,f))
9582 return 69;
9583
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_gstate,f))
9584 return 70;
9585
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trig_statetime,f))
9586 return 71;
9587
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_genscr,f))
9588 return 72;
9589
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_group,f))
9590 return 76;
9591
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_group_val,f))
9592 return 77;
9593
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_dir,f))
9594 return 89;
9595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_ind,f))
9596 return 90;
9597
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_levelitems,f))
9598 return 91;
9599
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigdmlevel,f))
9600 return 92;
9601
2/2
✓ Branch 0 taken 1380 times.
✓ Branch 1 taken 460 times.
1840 for(int q = 0; q < 3; ++q)
9602
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1380 times.
1380 if(!p_iputw(tmp_trig.trigtint[q],f))
9603 return 93;
9604
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.triglvlpalette,f))
9605 return 94;
9606
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigbosspalette,f))
9607 return 95;
9608
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigquaketime,f))
9609 return 96;
9610
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigwavytime,f))
9611 return 97;
9612
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_swjinxtime,f))
9613 return 98;
9614
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_itmjinxtime,f))
9615 return 99;
9616
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_stuntime,f))
9617 return 100;
9618
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_bunnytime,f))
9619 return 101;
9620
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trig_pushtime,f))
9621 return 102;
9622
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputw(tmp_trig.trig_shieldjinxtime, f))
9623 return 103;
9624
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.req_level_state, f))
9625 return 104;
9626
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.unreq_level_state, f))
9627 return 105;
9628
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.req_global_state, f))
9629 return 106;
9630
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_global_state, f))
9631 return 107;
9632
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.fail_prompt_cid, f))
9633 return 108;
9634
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.fail_prompt_cs, f))
9635 return 109;
9636
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.trig_msgstr, f))
9637 return 110;
9638
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.fail_msgstr, f))
9639 return 111;
9640
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.player_bounce, f))
9641 return 112;
9642
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_z, f))
9643 return 113;
9644
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.req_player_dir, f))
9645 return 114;
9646
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_x, f))
9647 return 115;
9648
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_y, f))
9649 return 116;
9650
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_z, f))
9651 return 117;
9652
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.req_player_jump, f))
9653 return 118;
9654
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_x, f))
9655 return 119;
9656
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_y, f))
9657 return 120;
9658
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.dest_player_dir, f))
9659 return 121;
9660
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.force_ice_combo, f))
9661 return 122;
9662
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.force_ice_vx, f))
9663 return 123;
9664
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.force_ice_vy, f))
9665 return 124;
9666
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_gravity, f))
9667 return 125;
9668
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_terminal_v, f))
9669 return 126;
9670
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.req_screen_state, f))
9671 return 127;
9672
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_screen_state, f))
9673 return 128;
9674
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.req_screen_ex_state, f))
9675 return 129;
9676
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_screen_ex_state, f))
9677 return 130;
9678
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trigstatemap, f))
9679 return 131;
9680
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trigstatescreen, f))
9681 return 132;
9682 460 return 0;
9683 460 }
9684 258906 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9685 {
9686 //Check what needs writing
9687 258906 word combo_has_flags = 0;
9688
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 2056150 times.
2311866 for(auto q = 0; q < 8; ++q)
9689 {
9690
4/4
✓ Branch 0 taken 2054470 times.
✓ Branch 1 taken 1680 times.
✓ Branch 2 taken 1028294 times.
✓ Branch 3 taken 1382 times.
3085826 if(tmp_cmb.attribytes[q] || tmp_cmb.attrishorts[q]
9691
4/4
✓ Branch 0 taken 2054342 times.
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 1029676 times.
✓ Branch 3 taken 1024666 times.
2054470 || (q < 4 && tmp_cmb.attributes[q]))
9692 {
9693 3190 combo_has_flags |= CHAS_ATTRIB;
9694 3190 break;
9695 }
9696 2052960 }
9697
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if (!tmp_cmb.triggers.empty())
9698 460 combo_has_flags |= CHAS_TRIG;
9699
4/4
✓ Branch 0 taken 258628 times.
✓ Branch 1 taken 278 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 258608 times.
258906 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9700 298 combo_has_flags |= CHAS_FLAG;
9701
6/6
✓ Branch 0 taken 251806 times.
✓ Branch 1 taken 7100 times.
✓ Branch 2 taken 231382 times.
✓ Branch 3 taken 20424 times.
✓ Branch 4 taken 532 times.
✓ Branch 5 taken 230732 times.
490170 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9702
6/6
✓ Branch 0 taken 231358 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 231320 times.
✓ Branch 3 taken 38 times.
✓ Branch 4 taken 231264 times.
✓ Branch 5 taken 56 times.
231382 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9703
1/2
✓ Branch 0 taken 231264 times.
✗ Branch 1 not taken.
231264 || tmp_cmb.animflags)
9704 28174 combo_has_flags |= CHAS_ANIM;
9705
3/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 258900 times.
258906 if(tmp_cmb.script || tmp_cmb.label.size())
9706 6 combo_has_flags |= CHAS_SCRIPT;
9707
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 2071200 times.
2330100 else for(auto q = 0; q < 8; ++q)
9708 {
9709
1/2
✓ Branch 0 taken 2071200 times.
✗ Branch 1 not taken.
2071200 if(tmp_cmb.initd[q])
9710 {
9711 combo_has_flags |= CHAS_SCRIPT;
9712 break;
9713 }
9714 2071200 }
9715
5/6
✓ Branch 0 taken 176904 times.
✓ Branch 1 taken 82002 times.
✓ Branch 2 taken 176392 times.
✓ Branch 3 taken 512 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 176392 times.
435298 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9716
2/4
✓ Branch 0 taken 176392 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 176392 times.
✗ Branch 3 not taken.
176392 || tmp_cmb.type || tmp_cmb.csets)
9717 82514 combo_has_flags |= CHAS_BASIC;
9718
3/4
✓ Branch 0 taken 258898 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
517802 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9719
3/6
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9720
4/6
✓ Branch 0 taken 258896 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258896 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9721
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9722
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9723
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9724
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lift_parent_item || !tmp_cmb.lift_weap_data.is_blank())
9725 10 combo_has_flags |= CHAS_LIFT;
9726
2/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258906 times.
✗ Branch 3 not taken.
515612 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9727
7/10
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258902 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 258898 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258906 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9728
5/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap
9729
6/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✓ Branch 3 taken 2192 times.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 256706 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.sfx_landing || tmp_cmb.spr_falling || tmp_cmb.spr_drowning || tmp_cmb.spr_lava_drowning || tmp_cmb.sfx_falling
9730
4/8
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
256706 || tmp_cmb.sfx_drowning || tmp_cmb.sfx_lava_drowning || tmp_cmb.z_height || tmp_cmb.z_step_height
9731
1/2
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
256706 || tmp_cmb.dive_under_level)
9732 258906 combo_has_flags |= CHAS_GENERAL;
9733
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!tmp_cmb.misc_weap_data.is_blank())
9734 combo_has_flags |= CHAS_MISC_WEAP_DATA;
9735
9736
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(combo_has_flags,f))
9737 {
9738 return 50;
9739 }
9740
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!combo_has_flags) return 0; //Valid, done writing
9741 //Write the combo
9742
2/2
✓ Branch 0 taken 176392 times.
✓ Branch 1 taken 82514 times.
258906 if(combo_has_flags&CHAS_BASIC)
9743 {
9744
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_iputl(tmp_cmb.o_tile,f))
9745 return 6;
9746
9747
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flip,f))
9748 return 7;
9749
9750
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.walk,f))
9751 return 8;
9752
9753
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.type,f))
9754 return 9;
9755
9756
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flag,f))
9757 return 15;
9758
9759
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.csets,f))
9760 return 10;
9761 82514 }
9762
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 6 times.
258906 if(combo_has_flags&CHAS_SCRIPT)
9763 {
9764 6 p_putcstr(tmp_cmb.label, f);
9765
9766
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(tmp_cmb.script,f))
9767 return 26;
9768
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for ( int32_t q = 0; q < 8; q++ )
9769
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(tmp_cmb.initd[q],f))
9770 return 27;
9771 6 }
9772
2/2
✓ Branch 0 taken 230732 times.
✓ Branch 1 taken 28174 times.
258906 if(combo_has_flags&CHAS_ANIM)
9773 {
9774
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.frames,f))
9775 return 11;
9776
9777
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.speed,f))
9778 return 12;
9779
9780
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_iputw(tmp_cmb.nextcombo,f))
9781 return 13;
9782
9783
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.nextcset,f))
9784 return 14;
9785
9786
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanim,f))
9787 return 16;
9788
9789
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanimy,f))
9790 return 18;
9791
9792
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.animflags,f))
9793 return 19;
9794 28174 }
9795
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 3190 times.
258906 if(combo_has_flags&CHAS_ATTRIB)
9796 {
9797
2/2
✓ Branch 0 taken 12760 times.
✓ Branch 1 taken 3190 times.
15950 for ( int32_t q = 0; q < 4; q++ )
9798
1/2
✓ Branch 0 taken 12760 times.
✗ Branch 1 not taken.
12760 if(!p_iputl(tmp_cmb.attributes[q],f))
9799 return 20;
9800
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ )
9801
1/2
✓ Branch 0 taken 25520 times.
✗ Branch 1 not taken.
25520 if(!p_putc(tmp_cmb.attribytes[q],f))
9802 return 25;
9803
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ ) //I also added attrishorts -Dimi
9804
1/2
✓ Branch 0 taken 25520 times.
✗ Branch 1 not taken.
25520 if(!p_iputw(tmp_cmb.attrishorts[q],f))
9805 return 32;
9806 3190 }
9807
2/2
✓ Branch 0 taken 258608 times.
✓ Branch 1 taken 298 times.
258906 if(combo_has_flags&CHAS_FLAG)
9808 {
9809
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputl(tmp_cmb.usrflags,f))
9810 return 21;
9811
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputw(tmp_cmb.genflags,f))
9812 return 33;
9813 298 }
9814
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if(combo_has_flags&CHAS_TRIG)
9815 {
9816
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 byte sz = zc_min(tmp_cmb.triggers.size(), 255);
9817
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(sz,f))
9818 return 34;
9819
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 460 times.
920 for(byte q = 0; q < sz; ++q)
9820 {
9821 460 auto ret = writecombo_triggers_loop(f, section_version, tmp_cmb.triggers[q]);
9822
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(ret) return ret;
9823 460 }
9824
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.only_gentrig,f))
9825 return 35;
9826 460 }
9827
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(combo_has_flags&CHAS_LIFT)
9828 {
9829
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftcmb,f))
9830 return 54;
9831
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftcs,f))
9832 return 55;
9833
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftundercmb,f))
9834 return 56;
9835
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftundercs,f))
9836 return 57;
9837
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftdmg,f))
9838 return 58;
9839
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftlvl,f))
9840 return 59;
9841
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftitm,f))
9842 return 60;
9843
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftflags,f))
9844 return 61;
9845
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftgfx,f))
9846 return 62;
9847
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsprite,f))
9848 return 63;
9849
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsfx,f))
9850 return 64;
9851
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9852 return 65;
9853
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9854 return 66;
9855
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifthei,f))
9856 return 67;
9857
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifttime,f))
9858 return 68;
9859
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lift_parent_item,f))
9860 return 78;
9861
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(auto ret = write_weap_data(tmp_cmb.lift_weap_data, f))
9862 return ret;
9863 258906 }
9864
2/2
✓ Branch 0 taken 256706 times.
✓ Branch 1 taken 2200 times.
258906 if(combo_has_flags&CHAS_GENERAL)
9865 {
9866
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_mult,f))
9867 return 73;
9868
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_div,f))
9869 return 74;
9870
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.speed_add,f))
9871 return 75;
9872
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_appear,f))
9873 return 79;
9874
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_disappear,f))
9875 return 80;
9876
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_loop,f))
9877 return 81;
9878
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_walking,f))
9879 return 82;
9880
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_standing,f))
9881 return 83;
9882
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_appear,f))
9883 return 84;
9884
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_disappear,f))
9885 return 85;
9886
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_walking,f))
9887 return 86;
9888
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_standing,f))
9889 return 87;
9890
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_tap,f))
9891 return 88;
9892
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_landing,f))
9893 return 89;
9894
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_falling,f))
9895 return 90;
9896
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_drowning,f))
9897 return 91;
9898
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_lava_drowning,f))
9899 return 92;
9900
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_falling,f))
9901 return 93;
9902
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_drowning,f))
9903 return 94;
9904
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_lava_drowning,f))
9905 return 95;
9906
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_height,f))
9907 return 96;
9908
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_step_height,f))
9909 return 97;
9910
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2200 times.
2200 if(!p_putc(tmp_cmb.dive_under_level,f))
9911 return 98;
9912 2200 }
9913
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(combo_has_flags&CHAS_MISC_WEAP_DATA)
9914 {
9915 if(auto ret = write_weap_data(tmp_cmb.misc_weap_data, f))
9916 return ret;
9917 }
9918 258906 return 0;
9919 258906 }
9920
9921 9 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9922 {
9923 //these are here to bypass compiler warnings about unused arguments
9924 9 version=version;
9925 9 build=build;
9926
9927 word combos_used;
9928 9 dword section_id=ID_COMBOS;
9929 9 dword section_version=V_COMBOS;
9930 // dword section_size=0;
9931 9 combos_used = count_combos()-start_combo;
9932
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, max_combos);
9933
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, MAXCOMBOS);
9934 9 dword section_size = 0;
9935
9936 //section id
9937
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9938 {
9939 new_return(1);
9940 }
9941
9942 //section version info
9943
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9944 {
9945 new_return(2);
9946 }
9947
9948
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
9949 {
9950 new_return(3);
9951 }
9952
9953
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9954 {
9955 18 fake_pack_writing=(writecycle==0);
9956
9957 //section size
9958
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9959 {
9960 new_return(4);
9961 }
9962
9963 18 writesize=0;
9964
9965 //finally... section data
9966 18 combos_used=count_combos()-start_combo;
9967
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, max_combos);
9968
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, MAXCOMBOS);
9969
9970
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(combos_used,f))
9971 {
9972 new_return(5);
9973 }
9974
9975 18 size_t end_combo = start_combo+combos_used;
9976
2/2
✓ Branch 0 taken 258906 times.
✓ Branch 1 taken 18 times.
258924 for(size_t q = start_combo; q < end_combo; ++q)
9977 {
9978 258906 auto ret = writecombo_loop(f, section_version, combobuf[q]);
9979
1/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
258906 if(ret) new_return(ret);
9980 258906 }
9981
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9982 {
9983 9 section_size=writesize;
9984 9 }
9985 18 }
9986
9987
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9988 {
9989 char ebuf[80];
9990 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9991 jwin_alert("Error: writecombos()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9992 }
9993
9994 9 new_return(0);
9995 9 }
9996
9997 9 int32_t writecomboaliases(PACKFILE *f, word version, word build)
9998 {
9999 //these are here to bypass compiler warnings about unused arguments
10000 9 version=version;
10001 9 build=build;
10002
10003 9 dword section_id=ID_COMBOALIASES;
10004 9 dword section_version=V_COMBOALIASES;
10005 9 dword section_size=0;
10006
10007 //section id
10008
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10009 {
10010 new_return(1);
10011 }
10012
10013 //section version info
10014
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10015 {
10016 new_return(2);
10017 }
10018
10019
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10020 {
10021 new_return(3);
10022 }
10023
10024
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10025 {
10026 18 fake_pack_writing=(writecycle==0);
10027
10028 //section size
10029
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10030 {
10031 new_return(4);
10032 }
10033
10034 18 writesize=0;
10035
10036 //finally... section data
10037
2/2
✓ Branch 0 taken 147456 times.
✓ Branch 1 taken 18 times.
147474 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
10038 {
10039
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_iputw(combo_aliases[j].combo,f))
10040 {
10041 new_return(5);
10042 }
10043
10044
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].cset,f))
10045 {
10046 new_return(6);
10047 }
10048
10049 147456 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
10050
10051
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].width,f))
10052 {
10053 new_return(7);
10054 }
10055
10056
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].height,f))
10057 {
10058 new_return(8);
10059 }
10060
10061
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].layermask,f))
10062 {
10063 new_return(9);
10064 }
10065
10066
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
10067 {
10068
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_iputw(combo_aliases[j].combos[k],f))
10069 {
10070 new_return(10);
10071 }
10072 149596 }
10073
10074
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
10075 {
10076
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_putc(combo_aliases[j].csets[k],f))
10077 {
10078 new_return(11);
10079 }
10080 149596 }
10081 147456 }
10082
10083 //Combo pools!
10084 int16_t num_cpools;
10085
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 147452 times.
147468 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10086 {
10087
2/2
✓ Branch 0 taken 147450 times.
✓ Branch 1 taken 2 times.
147452 if(combo_pools[num_cpools].valid()) //found a used pool
10088 {
10089 2 ++num_cpools;
10090 2 break;
10091 }
10092 147450 }
10093
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
18 if(num_cpools < 0) num_cpools = 0;
10094
10095
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_cpools,f))
10096 {
10097 new_return(12);
10098 }
10099
10100
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 18 times.
24 for(auto cp = 0; cp < num_cpools; ++cp)
10101 {
10102 6 combo_pool const& pool = combo_pools[cp];
10103 6 int32_t num_combos = pool.combos.size();
10104
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10105 {
10106 new_return(13);
10107 }
10108
10109
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10110 {
10111 26 cpool_entry const& entry = pool.combos.at(q);
10112
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10113 {
10114 new_return(14);
10115 }
10116
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10117 {
10118 new_return(15);
10119 }
10120
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(entry.quant,f))
10121 {
10122 new_return(16);
10123 }
10124 26 }
10125 6 }
10126
10127 //Autocombos!
10128 int16_t num_cautos;
10129
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 147456 times.
147474 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10130 {
10131
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if (combo_autos[num_cautos].valid()) //found a used autocombo
10132 {
10133 ++num_cautos;
10134 break;
10135 }
10136 147456 }
10137
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (num_cautos < 0) num_cautos = 0;
10138
10139
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(num_cautos, f))
10140 {
10141 new_return(17);
10142 }
10143
10144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for (auto ca = 0; ca < num_cautos; ++ca)
10145 {
10146 combo_auto const& cauto = combo_autos[ca];
10147 if (!p_putc(cauto.getType(), f))
10148 {
10149 new_return(18);
10150 }
10151 if (!p_iputl(cauto.getIconDisplay(), f))
10152 {
10153 new_return(19);
10154 }
10155 if (!p_iputl(cauto.getEraseCombo(), f))
10156 {
10157 new_return(20);
10158 }
10159 if (!p_putc(cauto.getFlags(), f))
10160 {
10161 new_return(21);
10162 }
10163 if (!p_putc(cauto.getArg(), f))
10164 {
10165 new_return(22);
10166 }
10167 int32_t num_combos = cauto.combos.size();
10168 if (!p_iputl(num_combos, f))
10169 {
10170 new_return(23);
10171 }
10172
10173 for (auto q = 0; q < num_combos; ++q)
10174 {
10175 autocombo_entry const& entry = cauto.combos.at(q);
10176 if (!p_putc(entry.ctype, f))
10177 {
10178 new_return(24);
10179 }
10180 if (!p_iputl(entry.cid, f))
10181 {
10182 new_return(25);
10183 }
10184 }
10185 }
10186
10187
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10188 {
10189 9 section_size=writesize;
10190 9 }
10191 18 }
10192
10193
10194
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10195 {
10196 char ebuf[80];
10197 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10198 jwin_alert("Error: writecomboaliases()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10199 }
10200
10201 9 new_return(0);
10202 }
10203
10204 9 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10205 {
10206 //these are here to bypass compiler warnings about unused arguments
10207 9 version=version;
10208 9 build=build;
10209 9 start_cset=start_cset;
10210 9 max_csets=max_csets;
10211
10212 9 dword section_id=ID_CSETS;
10213 9 dword section_version=V_CSETS;
10214 9 int32_t palcycles = count_palcycles(&QMisc);
10215 // int32_t palcyccount = count_palcycles(&QMisc);
10216 9 dword section_size = 0;
10217
10218 //section id
10219
10220
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10221 {
10222 new_return(1);
10223 }
10224
10225 //section version info
10226
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10227 {
10228 new_return(2);
10229 }
10230
10231
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10232 {
10233 new_return(3);
10234 }
10235
10236
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10237 {
10238 18 fake_pack_writing=(writecycle==0);
10239
10240 //section size
10241
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10242 {
10243 new_return(4);
10244 }
10245
10246 18 writesize=0;
10247
10248 //finally... section data
10249
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(colordata,psTOTAL255,f))
10250 {
10251 new_return(5);
10252 }
10253
10254
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10255 {
10256 new_return(6);
10257 }
10258
10259
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(palcycles,f))
10260 {
10261 new_return(15);
10262 }
10263
10264
2/2
✓ Branch 0 taken 550 times.
✓ Branch 1 taken 18 times.
568 for(int32_t i=0; i<palcycles; i++)
10265 {
10266
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10267 {
10268
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].first,f))
10269 {
10270 new_return(16);
10271 }
10272 1650 }
10273
10274
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10275 {
10276
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].count,f))
10277 {
10278 new_return(17);
10279 }
10280 1650 }
10281
10282
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10283 {
10284
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].speed,f))
10285 {
10286 new_return(18);
10287 }
10288 1650 }
10289 550 }
10290
10291
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10292 {
10293 9 section_size=writesize;
10294 9 }
10295 18 }
10296
10297
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10298 {
10299 char ebuf[80];
10300 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10301 jwin_alert("Error: writecolordata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10302 }
10303
10304 9 new_return(0);
10305 }
10306
10307 9 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10308 {
10309 //these are here to bypass compiler warnings about unused arguments
10310 9 version=version;
10311 9 build=build;
10312 9 start_msgstr=start_msgstr;
10313 9 max_msgstrs=max_msgstrs;
10314
10315 9 dword section_id=ID_STRINGS;
10316 9 dword section_version=V_STRINGS;
10317 9 dword section_size = 0;
10318
10319 //section id
10320
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10321 {
10322 new_return(1);
10323 }
10324
10325 //section version info
10326
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10327 {
10328 new_return(2);
10329 }
10330
10331
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10332 {
10333 new_return(3);
10334 }
10335
10336
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10337 {
10338 18 fake_pack_writing=(writecycle==0);
10339
10340 //section size
10341
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10342 {
10343 new_return(4);
10344 }
10345
10346 18 writesize=0;
10347
10348 //finally... section data
10349
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(msg_count,f))
10350 {
10351 return qe_invalid;
10352 }
10353
10354
2/2
✓ Branch 0 taken 836 times.
✓ Branch 1 taken 18 times.
854 for(int32_t i=0; i<msg_count; i++)
10355 {
10356 836 MsgStrings[i].ensureAsciiEncoding();
10357 836 int32_t sz = MsgStrings[i].s.size();
10358
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(sz > 8192) sz = 8192;
10359
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(sz, f))
10360 {
10361 return qe_invalid;
10362 }
10363
10364 836 char const* tmpstr = MsgStrings[i].s.c_str();
10365
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 836 times.
836 if (sz > 0)
10366 {
10367
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if (!pfwrite((void*)tmpstr,sz, f))
10368 {
10369 return qe_invalid;
10370 }
10371 836 }
10372
10373
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].nextstring,f))
10374 {
10375 return qe_invalid;
10376 }
10377
10378
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].tile,f))
10379 {
10380 return qe_invalid;
10381 }
10382
10383
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].cset,f))
10384 {
10385 return qe_invalid;
10386 }
10387
10388
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].trans?1:0,f))
10389 {
10390 return qe_invalid;
10391 }
10392
10393
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].font,f))
10394 {
10395 return qe_invalid;
10396 }
10397
10398
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].x,f))
10399 {
10400 return qe_invalid;
10401 }
10402
10403
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].y,f))
10404 {
10405 return qe_invalid;
10406 }
10407
10408
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].w,f))
10409 {
10410 return qe_invalid;
10411 }
10412
10413
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].h,f))
10414 {
10415 return qe_invalid;
10416 }
10417
10418
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].hspace,f))
10419 {
10420 return qe_invalid;
10421 }
10422
10423
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].vspace,f))
10424 {
10425 return qe_invalid;
10426 }
10427
10428
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].stringflags,f))
10429 {
10430 return qe_invalid;
10431 }
10432
10433
2/2
✓ Branch 0 taken 3344 times.
✓ Branch 1 taken 836 times.
4180 for(int32_t q = 0; q < 4; ++q)
10434 {
10435
1/2
✓ Branch 0 taken 3344 times.
✗ Branch 1 not taken.
3344 if(!p_putc(MsgStrings[i].margins[q],f))
10436 {
10437 return qe_invalid;
10438 }
10439 3344 }
10440
10441
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10442 {
10443 return qe_invalid;
10444 }
10445
10446
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_cset,f))
10447 {
10448 return qe_invalid;
10449 }
10450
10451
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_x,f))
10452 {
10453 return qe_invalid;
10454 }
10455
10456
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_y,f))
10457 {
10458 return qe_invalid;
10459 }
10460
10461
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_tw,f))
10462 {
10463 return qe_invalid;
10464 }
10465
10466
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_th,f))
10467 {
10468 return qe_invalid;
10469 }
10470
10471
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_type,f))
10472 {
10473 return qe_invalid;
10474 }
10475
10476
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_color,f))
10477 {
10478 return qe_invalid;
10479 }
10480
10481
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].drawlayer,f))
10482 {
10483 return qe_invalid;
10484 }
10485
10486
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].sfx,f))
10487 {
10488 return qe_invalid;
10489 }
10490
10491
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].listpos,f))
10492 {
10493 return qe_invalid;
10494 }
10495 836 }
10496
10497
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10498 {
10499 9 section_size=writesize;
10500 9 }
10501 18 }
10502
10503
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10504 {
10505 char ebuf[80];
10506 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10507 jwin_alert("Error: writestrings()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10508 }
10509
10510 9 new_return(0);
10511 9 }
10512
10513 int32_t writestrings_text(PACKFILE *f)
10514 {
10515 std::map<int32_t, int32_t> msglistcache;
10516
10517 for(int32_t index = 1; index<msg_count; index++)
10518 {
10519 for(int32_t i=1; i<msg_count; i++)
10520 {
10521 if(MsgStrings[i].listpos==index)
10522 {
10523 msglistcache[index-1]=i;
10524 break;
10525 }
10526 }
10527 }
10528
10529 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10530 {
10531 fake_pack_writing=(writecycle==0);
10532 char ebuf[32];
10533
10534 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10535
10536 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10537 {
10538 return qe_invalid;
10539 }
10540
10541 for(int32_t i=1; i<msg_count; i++)
10542 {
10543 int32_t str = msglistcache[i-1];
10544
10545 if(!str)
10546 continue;
10547
10548 if(MsgStrings[str].nextstring != 0)
10549 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10550 else
10551 sprintf(ebuf,"\n\n___%d___\n", str);
10552
10553 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10554 {
10555 return qe_invalid;
10556 }
10557
10558 std::string text = MsgStrings[str].serialize();
10559 if (!pfwrite(text.c_str(), text.size(), f))
10560 {
10561 return qe_invalid;
10562 }
10563 }
10564 }
10565
10566 new_return(0);
10567 }
10568
10569 1 int32_t writestrings_tsv(PACKFILE *f)
10570 {
10571 1 std::stringstream ss;
10572
10573
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10574
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){ return msg.serialize(); }},
10575
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10576
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10577
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10578
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10579
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10580
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10581
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10582
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10583
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10584
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10585
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10586
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10587
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10588
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10589
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10590
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10591
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10592
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10593
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10594
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10595
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10596
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10597
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10598
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10599 };
10600
10601
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10602 {
10603
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10604
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10605 1 break;
10606
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10607 }
10608
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10609
10610 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10611
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10612
10613
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10614 {
10615 35 auto& msg = MsgStrings[i];
10616
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10617 {
10618
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10619
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10620
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10621 35 break;
10622
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10623
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10624
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10625 35 }
10626
10627
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10628
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10629 {
10630 return qe_invalid;
10631 }
10632
10633 1 new_return(0);
10634 1 }
10635
10636 void parse_strings_tsv(std::string tsv)
10637 {
10638 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10639 { "message", [](auto& msg, auto& text){ msg.setFromAsciiEncoding(text); } },
10640 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10641 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10642 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10643 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10644 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10645 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10646 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10647 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10648 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10649 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10650 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10651 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10652 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10653 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10654 { "margin", [&](auto& msg, auto& text){
10655 std::vector<std::string> strs;
10656 util::split(text, strs, ' ');
10657 if (strs.size() != 4)
10658 throw std::runtime_error("margin field must have 4 components");
10659 msg.margins[0] = std::stoi(strs[0]);
10660 msg.margins[1] = std::stoi(strs[1]);
10661 msg.margins[2] = std::stoi(strs[2]);
10662 msg.margins[3] = std::stoi(strs[3]);
10663 } },
10664 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10665 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10666 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10667 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10668 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10669 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10670 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10671 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10672 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10673 };
10674
10675 std::vector<std::string> rows;
10676 util::split(tsv, rows, '\n');
10677 if (rows.size())
10678 {
10679 std::string last = rows.back();
10680 util::trimstr(last);
10681 if (last.empty())
10682 rows.pop_back();
10683 }
10684 if (rows.size() <= 1)
10685 throw std::runtime_error("missing header row");
10686
10687 std::vector<std::string> columns;
10688 util::split(rows[0], columns, '\t');
10689 for (auto name : columns)
10690 {
10691 if (!fields.contains(name))
10692 throw std::runtime_error(fmt::format("invalid field: {}", name));
10693 }
10694
10695 int start_index = 1;
10696 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10697 start_index += 1;
10698
10699 int num_strings = rows.size() - start_index + 1;
10700 if (num_strings > MAXMSGS-1)
10701 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10702
10703 std::vector<MsgStr> msgs;
10704 msgs.reserve(num_strings);
10705 for (int i = start_index; i < rows.size(); i++)
10706 {
10707 std::vector<std::string> strs;
10708 util::split(rows[i], strs, '\t');
10709 if (strs.size() != columns.size())
10710 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10711
10712 int j = 0;
10713 auto& msg = msgs.emplace_back();
10714 for (auto& name : columns)
10715 {
10716 auto& fn = fields[name];
10717 try
10718 {
10719 fn(msg, strs[j++]);
10720 }
10721 catch (std::exception& ex)
10722 {
10723 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10724 }
10725 }
10726 }
10727
10728 init_msgstrings(0, msgs.size());
10729 for (int i = 0; i < msgs.size(); i++)
10730 MsgStrings[i + 1] = msgs[i];
10731 msg_count = msgs.size() + 1;
10732 msglistcache.clear();
10733 }
10734
10735 bool isblanktile(tiledata *buf, int32_t i);
10736 9 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10737 {
10738 //these are here to bypass compiler warnings about unused arguments
10739 9 version=version;
10740 9 build=build;
10741
10742 int32_t tiles_used;
10743 9 dword section_id=ID_TILES;
10744 9 dword section_version=V_TILES;
10745 9 al_trace("Counting tiles used\n");
10746 9 tiles_used = count_tiles(newtilebuf)-start_tile;
10747
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, max_tiles);
10748
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10749 9 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10750 9 dword section_size = 0;
10751
10752 //section id
10753
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10754 {
10755 new_return(1);
10756 }
10757
10758 //section version info
10759
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10760 {
10761 new_return(2);
10762 }
10763
10764
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10765 {
10766 new_return(3);
10767 }
10768
10769
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10770 {
10771 18 fake_pack_writing=(writecycle==0);
10772
10773 //section size
10774
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10775 {
10776 new_return(4);
10777 }
10778
10779 18 writesize=0;
10780
10781 //finally... section data
10782 18 tiles_used=count_tiles(newtilebuf)-start_tile;
10783
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, max_tiles);
10784
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10785
10786
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(tiles_used,f))
10787 {
10788 new_return(5);
10789 }
10790
10791
2/2
✓ Branch 0 taken 696384 times.
✓ Branch 1 taken 18 times.
696402 for(int32_t i=0; i<tiles_used; ++i)
10792 {
10793
2/2
✓ Branch 0 taken 365770 times.
✓ Branch 1 taken 330614 times.
696384 if(isblanktile(newtilebuf, start_tile+i))
10794 {
10795
1/2
✓ Branch 0 taken 365770 times.
✗ Branch 1 not taken.
365770 if(!p_putc(0,f))
10796 new_return(8);
10797 365770 }
10798 else
10799 {
10800 330614 int format = newtilebuf[start_tile+i].format;
10801
1/2
✓ Branch 0 taken 330614 times.
✗ Branch 1 not taken.
330614 if(!p_putc(format,f))
10802 {
10803 new_return(6);
10804 }
10805
10806
2/2
✓ Branch 0 taken 327742 times.
✓ Branch 1 taken 2872 times.
330614 if (format == tf4Bit)
10807 {
10808 byte temp_tile[128];
10809 327742 byte *di = temp_tile;
10810 327742 byte *src = newtilebuf[start_tile+i].data;
10811
2/2
✓ Branch 0 taken 41950976 times.
✓ Branch 1 taken 327742 times.
42278718 for (int32_t si=0; si<256; si+=2)
10812 {
10813 41950976 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10814 41950976 ++di;
10815 41950976 }
10816
1/2
✓ Branch 0 taken 327742 times.
✗ Branch 1 not taken.
327742 if (!pfwrite(temp_tile,128,f))
10817 {
10818 new_return(7);
10819 }
10820 327742 }
10821
1/2
✓ Branch 0 taken 2872 times.
✗ Branch 1 not taken.
2872 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10822 {
10823 new_return(7);
10824 }
10825 }
10826 696384 }
10827
10828
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10829 {
10830 9 section_size=writesize;
10831 9 }
10832 18 }
10833
10834
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10835 {
10836 char ebuf[80];
10837 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10838 jwin_alert("Error: writetiles()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10839 }
10840
10841 9 new_return(0);
10842 }
10843
10844 /* MIDI Format
10845 section_id LONG
10846 section_version WORD
10847 section_cversion WORD
10848 section_size LONG
10849 midi_flags 32 Byte ? BITFIELD[252]
10850
10851 [
10852 title 36
10853 start 4
10854 loop_start 4
10855 loop_end 4
10856 loop 2
10857 volume 2
10858 midi *
10859 ]
10860
10861 */
10862
10863 9 int32_t writemidis(PACKFILE *f)
10864 {
10865 9 dword section_id=ID_MIDIS;
10866 9 dword section_version=V_MIDIS;
10867 9 dword section_size = 0;
10868
10869 //section id
10870
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10871 {
10872 new_return(1);
10873 }
10874
10875 //section version info
10876
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10877 {
10878 new_return(2);
10879 }
10880
10881
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10882 {
10883 new_return(3);
10884 }
10885
10886
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10887 {
10888 18 fake_pack_writing=(writecycle==0);
10889
10890 //section size
10891
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10892 {
10893 new_return(4);
10894 }
10895
10896 18 writesize=0;
10897
10898 //finally... section data
10899
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10900 {
10901 new_return(5);
10902 }
10903
10904
2/2
✓ Branch 0 taken 4536 times.
✓ Branch 1 taken 18 times.
4554 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10905 {
10906
2/2
✓ Branch 0 taken 4406 times.
✓ Branch 1 taken 130 times.
4536 if(get_bit(midi_flags,i))
10907 {
10908
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10909 {
10910 new_return(6);
10911 }
10912
10913
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].start,f))
10914 {
10915 new_return(7);
10916 }
10917
10918
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_start,f))
10919 {
10920 new_return(8);
10921 }
10922
10923
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_end,f))
10924 {
10925 new_return(9);
10926 }
10927
10928
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].loop,f))
10929 {
10930 new_return(10);
10931 }
10932
10933
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].volume,f))
10934 {
10935 new_return(11);
10936 }
10937
10938
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
10939 {
10940 new_return(12);
10941 }
10942
10943 130 byte format = MFORMAT_MIDI;
10944
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&format, sizeof(format),f))
10945 {
10946 new_return(13);
10947 }
10948
10949
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (!write_midi(customtunes[i].data, f)) new_return(14);
10950 130 }
10951 4536 }
10952
10953
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10954 {
10955 9 section_size=writesize;
10956 9 }
10957 18 }
10958
10959
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10960 {
10961 char ebuf[80];
10962 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10963 jwin_alert("Error: writemidis()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10964 }
10965
10966 9 new_return(0);
10967 }
10968
10969 9 int32_t writecheats(PACKFILE *f, zquestheader *Header)
10970 {
10971 9 dword section_id=ID_CHEATS;
10972 9 dword section_version=V_CHEATS;
10973 9 dword section_size = 0;
10974
10975 //section id
10976
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10977 {
10978 new_return(1);
10979 }
10980
10981 //section version info
10982
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10983 {
10984 new_return(2);
10985 }
10986
10987
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10988 {
10989 new_return(3);
10990 }
10991
10992
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10993 {
10994 18 fake_pack_writing=(writecycle==0);
10995
10996 //section size
10997
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10998 {
10999 new_return(4);
11000 }
11001
11002 18 writesize=0;
11003
11004 //finally... section data
11005
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
11006 {
11007 new_return(5);
11008 }
11009
11010
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(Header->data_flags[ZQ_CHEATS2])
11011 {
11012
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zcheats.flags,f))
11013 {
11014 new_return(6);
11015 }
11016
11017
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
11018 {
11019 new_return(7);
11020 }
11021 18 }
11022
11023
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
11024 {
11025 9 section_size=writesize;
11026 9 }
11027 18 }
11028
11029
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
11030 {
11031 char ebuf[80];
11032 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11033 jwin_alert("Error: writecheats()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11034 }
11035
11036 9 new_return(0);
11037 }
11038
11039 9 int32_t writeguys(PACKFILE *f, zquestheader *Header)
11040 {
11041 //these are here to bypass compiler warnings about unused arguments
11042 9 Header=Header;
11043
11044 9 dword section_id=ID_GUYS;
11045 9 dword section_version=V_GUYS;
11046 9 dword section_size=0;
11047
11048 //section id
11049
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
11050 {
11051 new_return(1);
11052 }
11053
11054 //section version info
11055
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
11056 {
11057 new_return(2);
11058 }
11059
11060
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
11061 {
11062 new_return(3);
11063 }
11064
11065
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11066 {
11067 18 fake_pack_writing=(writecycle==0);
11068
11069 //section size
11070
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11071 {
11072 new_return(4);
11073 }
11074
11075 18 writesize=0;
11076
11077 //finally... section data
11078
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11079 {
11080
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite((char *)guy_string[i], 64, f))
11081 {
11082 new_return(5);
11083 }
11084 9216 }
11085
11086
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11087 {
11088 9216 uint32_t flags1 = uint32_t(guysbuf[i].flags);
11089 9216 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
11090
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags1, f))
11091 {
11092 new_return(6);
11093 }
11094
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags2, f))
11095 {
11096 new_return(7);
11097 }
11098
11099
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tile,f))
11100 {
11101 new_return(8);
11102 }
11103
11104
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].width,f))
11105 {
11106 new_return(9);
11107 }
11108
11109
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].height,f))
11110 {
11111 new_return(10);
11112 }
11113
11114
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].s_tile,f))
11115 {
11116 new_return(11);
11117 }
11118
11119
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_width,f))
11120 {
11121 new_return(12);
11122 }
11123
11124
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_height,f))
11125 {
11126 new_return(13);
11127 }
11128
11129
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].e_tile,f))
11130 {
11131 new_return(14);
11132 }
11133
11134
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_width,f))
11135 {
11136 new_return(15);
11137 }
11138
11139
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_height,f))
11140 {
11141 new_return(16);
11142 }
11143
11144
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hp,f))
11145 {
11146 new_return(17);
11147 }
11148
11149
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].type,f))
11150 {
11151 new_return(18);
11152 }
11153
11154
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].cset,f))
11155 {
11156 new_return(19);
11157 }
11158
11159
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].anim,f))
11160 {
11161 new_return(20);
11162 }
11163
11164
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_anim,f))
11165 {
11166 new_return(21);
11167 }
11168
11169
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].frate,f))
11170 {
11171 new_return(22);
11172 }
11173
11174
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_frate,f))
11175 {
11176 new_return(23);
11177 }
11178
11179
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].dp,f))
11180 {
11181 new_return(24);
11182 }
11183
11184
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].wdp,f))
11185 {
11186 new_return(25);
11187 }
11188
11189
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].weapon,f))
11190 {
11191 new_return(26);
11192 }
11193
11194
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].rate,f))
11195 {
11196 new_return(27);
11197 }
11198
11199
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hrate,f))
11200 {
11201 new_return(28);
11202 }
11203
11204
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].step,f))
11205 {
11206 new_return(29);
11207 }
11208
11209
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].homing,f))
11210 {
11211 new_return(30);
11212 }
11213
11214
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].grumble,f))
11215 {
11216 new_return(31);
11217 }
11218
11219
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].item_set,f))
11220 {
11221 new_return(32);
11222 }
11223
11224
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[0], f))
11225 {
11226 new_return(33);
11227 }
11228
11229
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[1],f))
11230 {
11231 new_return(34);
11232 }
11233
11234
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[2],f))
11235 {
11236 new_return(35);
11237 }
11238
11239
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[3],f))
11240 {
11241 new_return(36);
11242 }
11243
11244
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[4],f))
11245 {
11246 new_return(37);
11247 }
11248
11249
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[5],f))
11250 {
11251 new_return(38);
11252 }
11253
11254
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[6],f))
11255 {
11256 new_return(39);
11257 }
11258
11259
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[7],f))
11260 {
11261 new_return(40);
11262 }
11263
11264
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[8],f))
11265 {
11266 new_return(41);
11267 }
11268
11269
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[9],f))
11270 {
11271 new_return(42);
11272 }
11273
11274
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bgsfx,f))
11275 {
11276 new_return(43);
11277 }
11278
11279
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bosspal,f))
11280 {
11281 new_return(44);
11282 }
11283
11284
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].extend,f))
11285 {
11286 new_return(45);
11287 }
11288
11289
2/2
✓ Branch 0 taken 175104 times.
✓ Branch 1 taken 9216 times.
184320 for(int32_t j=0; j < edefLAST; j++)
11290 {
11291
1/2
✓ Branch 0 taken 175104 times.
✗ Branch 1 not taken.
175104 if(!p_putc(guysbuf[i].defense[j],f))
11292 {
11293 new_return(46);
11294 }
11295 175104 }
11296
11297
5/6
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6144 times.
✓ Branch 3 taken 3072 times.
✓ Branch 4 taken 2048 times.
✓ Branch 5 taken 4096 times.
9216 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11298 {
11299 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11300
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2048 times.
2048 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11301 //Force SFX_HIT here.
11302
11303 2048 }
11304
11305
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].hitsfx,f))
11306 {
11307 new_return(47);
11308 }
11309
11310
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].deadsfx,f))
11311 {
11312 new_return(48);
11313 }
11314
11315
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[10],f))
11316 {
11317 new_return(49);
11318 }
11319
11320
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[11],f))
11321 {
11322 new_return(50);
11323 }
11324
11325 //New 2.6 defences
11326
2/2
✓ Branch 0 taken 202752 times.
✓ Branch 1 taken 9216 times.
211968 for(int32_t j=edefLAST; j < edefLAST255; j++)
11327 {
11328
1/2
✓ Branch 0 taken 202752 times.
✗ Branch 1 not taken.
202752 if(!p_putc(guysbuf[i].defense[j],f))
11329 {
11330 new_return(51);
11331 }
11332 202752 }
11333
11334 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11335
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].txsz,f))
11336 {
11337 new_return(52);
11338 }
11339
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tysz,f))
11340 {
11341 new_return(53);
11342 }
11343
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxsz,f))
11344 {
11345 new_return(54);
11346 }
11347
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hysz,f))
11348 {
11349 new_return(55);
11350 }
11351
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hzsz,f))
11352 {
11353 new_return(56);
11354 }
11355 // These are not fixed types, but ints, so they are safe to use here.
11356
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxofs,f))
11357 {
11358 new_return(57);
11359 }
11360
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hyofs,f))
11361 {
11362 new_return(58);
11363 }
11364
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].xofs,f))
11365 {
11366 new_return(59);
11367 }
11368
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].yofs,f))
11369 {
11370 new_return(60);
11371 }
11372
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].zofs,f))
11373 {
11374 new_return(61);
11375 }
11376
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].wpnsprite,f))
11377 {
11378 new_return(62);
11379 }
11380
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].SIZEflags,f))
11381 {
11382 new_return(63);
11383 }
11384
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozentile,f))
11385 {
11386 new_return(64);
11387 }
11388
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozencset,f))
11389 {
11390 new_return(65);
11391 }
11392
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozenclock,f))
11393 {
11394 new_return(66);
11395 }
11396
11397
2/2
✓ Branch 0 taken 92160 times.
✓ Branch 1 taken 9216 times.
101376 for ( int32_t q = 0; q < 10; q++ )
11398 {
11399
1/2
✓ Branch 0 taken 92160 times.
✗ Branch 1 not taken.
92160 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11400 {
11401 new_return(67);
11402 }
11403 92160 }
11404
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].firesfx,f))
11405 {
11406 new_return(68);
11407 }
11408 //misc 16->31
11409
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[15],f))
11410 {
11411 new_return(69);
11412 }
11413
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[16],f))
11414 {
11415 new_return(70);
11416 }
11417
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[17],f))
11418 {
11419 new_return(71);
11420 }
11421
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[18],f))
11422 {
11423 new_return(72);
11424 }
11425
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[19],f))
11426 {
11427 new_return(73);
11428 }
11429
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[20],f))
11430 {
11431 new_return(74);
11432 }
11433
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[21],f))
11434 {
11435 new_return(75);
11436 }
11437
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[22],f))
11438 {
11439 new_return(76);
11440 }
11441
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[23],f))
11442 {
11443 new_return(77);
11444 }
11445
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[24],f))
11446 {
11447 new_return(78);
11448 }
11449
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[25],f))
11450 {
11451 new_return(79);
11452 }
11453
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[26],f))
11454 {
11455 new_return(80);
11456 }
11457
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[27],f))
11458 {
11459 new_return(81);
11460 }
11461
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[28],f))
11462 {
11463 new_return(82);
11464 }
11465
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[29],f))
11466 {
11467 new_return(83);
11468 }
11469
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[30],f))
11470 {
11471 new_return(84);
11472 }
11473
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[31],f))
11474 {
11475 new_return(85);
11476 }
11477
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11478 {
11479
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].movement[q],f))
11480 {
11481 new_return(86);
11482 }
11483 294912 }
11484
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11485 {
11486
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11487 {
11488 new_return(87);
11489 }
11490 294912 }
11491
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].script,f))
11492 {
11493 new_return(88);
11494 }
11495
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11496 {
11497
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(guysbuf[i].initD[q],f))
11498 {
11499 new_return(89);
11500 }
11501 73728 }
11502
2/2
✓ Branch 0 taken 18432 times.
✓ Branch 1 taken 9216 times.
27648 for ( int32_t q = 0; q < 2; q++ )
11503 {
11504
1/2
✓ Branch 0 taken 18432 times.
✗ Branch 1 not taken.
18432 if(!p_iputl(0,f))
11505 {
11506 new_return(90);
11507 }
11508 18432 }
11509
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].editorflags,f))
11510 {
11511 new_return(91);
11512 }
11513 //somehow forgot these in the older builds -Z
11514
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[12],f))
11515 {
11516 new_return(92);
11517 }
11518
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[13],f))
11519 {
11520 new_return(93);
11521 }
11522
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[14],f))
11523 {
11524 new_return(94);
11525 }
11526
11527 //Enemy Editor InitD[] labels
11528
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11529 {
11530
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
11531 {
11532
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11533 {
11534 new_return(95);
11535 }
11536 4792320 }
11537 73728 }
11538
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].moveflags,f))
11539 new_return(99);
11540
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_shadow,f))
11541 new_return(100);
11542
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_death,f))
11543 new_return(101);
11544
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_spawn,f))
11545 new_return(102);
11546
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(guysbuf[i].specialsfx, f))
11547 new_return(103);
11548
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if(auto ret = write_weap_data(guysbuf[i].weap_data, f))
11549 return ret;
11550 9216 }
11551
11552
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
11553 {
11554 9 section_size=writesize;
11555 9 }
11556 18 }
11557
11558
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
11559 {
11560 char ebuf[80];
11561 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11562 jwin_alert("Error: writeguys()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11563 }
11564
11565 9 new_return(0);
11566 9 }
11567
11568 9 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11569 {
11570 //these are here to bypass compiler warnings about unused arguments
11571 9 Header=Header;
11572
11573 9 dword section_id=ID_HEROSPRITES;
11574 9 dword section_version=V_HEROSPRITES;
11575 9 dword section_size=0;
11576
11577 //section id
11578
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
11579 {
11580 new_return(1);
11581 }
11582
11583 //section version info
11584
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
11585 {
11586 new_return(2);
11587 }
11588
11589
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
11590 {
11591 new_return(3);
11592 }
11593
11594
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11595 {
11596 18 fake_pack_writing=(writecycle==0);
11597
11598 //section size
11599
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11600 {
11601 new_return(4);
11602 }
11603
11604 18 writesize=0;
11605
11606 //finally... section data
11607
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11608 {
11609
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(walkspr[i][spr_tile],f))
11610 {
11611 new_return(5);
11612 }
11613
11614
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_flip],f))
11615 {
11616 new_return(5);
11617 }
11618
11619
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_extend],f))
11620 {
11621 new_return(5);
11622 }
11623 72 }
11624
11625
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11626 {
11627
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stabspr[i][spr_tile],f))
11628 {
11629 new_return(6);
11630 }
11631
11632
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_flip],f))
11633 {
11634 new_return(6);
11635 }
11636
11637
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_extend],f))
11638 {
11639 new_return(6);
11640 }
11641 72 }
11642
11643
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11644 {
11645
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashspr[i][spr_tile],f))
11646 {
11647 new_return(7);
11648 }
11649
11650
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_flip],f))
11651 {
11652 new_return(7);
11653 }
11654
11655
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_extend],f))
11656 {
11657 new_return(7);
11658 }
11659 72 }
11660
11661
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11662 {
11663
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(floatspr[i][spr_tile],f))
11664 {
11665 new_return(8);
11666 }
11667
11668
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_flip],f))
11669 {
11670 new_return(8);
11671 }
11672
11673
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_extend],f))
11674 {
11675 new_return(8);
11676 }
11677 72 }
11678
11679
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11680 {
11681
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(swimspr[i][spr_tile],f))
11682 {
11683 new_return(8);
11684 }
11685
11686
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_flip],f))
11687 {
11688 new_return(8);
11689 }
11690
11691
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_extend],f))
11692 {
11693 new_return(8);
11694 }
11695 72 }
11696
11697
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11698 {
11699
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(divespr[i][spr_tile],f))
11700 {
11701 new_return(9);
11702 }
11703
11704
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_flip],f))
11705 {
11706 new_return(9);
11707 }
11708
11709
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_extend],f))
11710 {
11711 new_return(9);
11712 }
11713 72 }
11714
11715
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11716 {
11717
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(poundspr[i][spr_tile],f))
11718 {
11719 new_return(10);
11720 }
11721
11722
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_flip],f))
11723 {
11724 new_return(10);
11725 }
11726
11727
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_extend],f))
11728 {
11729 new_return(10);
11730 }
11731 72 }
11732
11733
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(castingspr[spr_tile],f))
11734 {
11735 new_return(11);
11736 }
11737
11738
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_flip],f))
11739 {
11740 new_return(11);
11741 }
11742
11743
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_extend],f))
11744 {
11745 new_return(11);
11746 }
11747
11748
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 for(int32_t i=0; i<2; i++)
11749 {
11750
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 36 times.
144 for(int32_t j=0; j<spr_holdmax; j++)
11751 {
11752
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(holdspr[i][j][spr_tile],f))
11753 {
11754 new_return(12);
11755 }
11756
11757
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11758 {
11759 new_return(12);
11760 }
11761
11762
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11763 {
11764 new_return(12);
11765 }
11766 108 }
11767 36 }
11768
11769
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11770 {
11771
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(jumpspr[i][spr_tile],f))
11772 {
11773 new_return(13);
11774 }
11775
11776
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11777 {
11778 new_return(13);
11779 }
11780
11781
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11782 {
11783 new_return(13);
11784 }
11785 72 }
11786
11787
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11788 {
11789
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(chargespr[i][spr_tile],f))
11790 {
11791 new_return(13);
11792 }
11793
11794
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_flip],f))
11795 {
11796 new_return(13);
11797 }
11798
11799
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_extend],f))
11800 {
11801 new_return(13);
11802 }
11803 72 }
11804
11805
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)zinit.hero_swim_speed,f))
11806 {
11807 new_return(14);
11808 }
11809
11810 //{ V_HEROSPRITES >= 7
11811
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11812 {
11813
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozenspr[q][spr_tile],f))
11814 new_return(15);
11815
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11816 new_return(15);
11817
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11818 new_return(15);
11819 72 }
11820
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11821 {
11822
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11823 new_return(15);
11824
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11825 new_return(15);
11826
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11827 new_return(15);
11828 72 }
11829
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11830 {
11831
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfirespr[q][spr_tile],f))
11832 new_return(15);
11833
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11834 new_return(15);
11835
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11836 new_return(15);
11837 72 }
11838
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11839 {
11840
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11841 new_return(15);
11842
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11843 new_return(15);
11844
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11845 new_return(15);
11846 72 }
11847
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11848 {
11849
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(diggingspr[q][spr_tile],f))
11850 new_return(15);
11851
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11852 new_return(15);
11853
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11854 new_return(15);
11855 72 }
11856
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11857 {
11858
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingrodspr[q][spr_tile],f))
11859 new_return(15);
11860
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11861 new_return(15);
11862
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11863 new_return(15);
11864 72 }
11865
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11866 {
11867
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingcanespr[q][spr_tile],f))
11868 new_return(15);
11869
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11870 new_return(15);
11871
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11872 new_return(15);
11873 72 }
11874
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11875 {
11876
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pushingspr[q][spr_tile],f))
11877 new_return(15);
11878
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11879 new_return(15);
11880
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11881 new_return(15);
11882 72 }
11883
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11884 {
11885
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingspr[q][spr_tile],f))
11886 new_return(15);
11887
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11888 new_return(15);
11889
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11890 new_return(15);
11891
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11892 new_return(15);
11893 72 }
11894
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11895 {
11896
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
11897 new_return(15);
11898
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
11899 new_return(15);
11900
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
11901 new_return(15);
11902 72 }
11903
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11904 {
11905
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunnedspr[q][spr_tile],f))
11906 new_return(15);
11907
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
11908 new_return(15);
11909
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
11910 new_return(15);
11911 72 }
11912
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11913 {
11914
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
11915 new_return(15);
11916
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
11917 new_return(15);
11918
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
11919 new_return(15);
11920 72 }
11921
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11922 {
11923
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowningspr[q][spr_tile],f))
11924 new_return(15);
11925
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_flip],f))
11926 new_return(15);
11927
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_extend],f))
11928 new_return(15);
11929 72 }
11930
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11931 {
11932
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
11933 new_return(15);
11934
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
11935 new_return(15);
11936
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
11937 new_return(15);
11938 72 }
11939
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11940 {
11941
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(fallingspr[q][spr_tile],f))
11942 new_return(15);
11943
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_flip],f))
11944 new_return(15);
11945
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_extend],f))
11946 new_return(15);
11947 72 }
11948
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11949 {
11950
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shockedspr[q][spr_tile],f))
11951 new_return(15);
11952
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_flip],f))
11953 new_return(15);
11954
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_extend],f))
11955 new_return(15);
11956 72 }
11957
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11958 {
11959
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
11960 new_return(15);
11961
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
11962 new_return(15);
11963
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
11964 new_return(15);
11965 72 }
11966
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11967 {
11968
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pullswordspr[q][spr_tile],f))
11969 new_return(15);
11970
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
11971 new_return(15);
11972
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
11973 new_return(15);
11974 72 }
11975
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11976 {
11977
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(readingspr[q][spr_tile],f))
11978 new_return(15);
11979
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_flip],f))
11980 new_return(15);
11981
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_extend],f))
11982 new_return(15);
11983 72 }
11984
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11985 {
11986
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slash180spr[q][spr_tile],f))
11987 new_return(15);
11988
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_flip],f))
11989 new_return(15);
11990
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_extend],f))
11991 new_return(15);
11992 72 }
11993
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11994 {
11995
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashZ4spr[q][spr_tile],f))
11996 new_return(15);
11997
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
11998 new_return(15);
11999
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
12000 new_return(15);
12001 72 }
12002
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12003 {
12004
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(dashspr[q][spr_tile],f))
12005 new_return(15);
12006
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_flip],f))
12007 new_return(15);
12008
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_extend],f))
12009 new_return(15);
12010 72 }
12011
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12012 {
12013
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(bonkspr[q][spr_tile],f))
12014 new_return(15);
12015
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_flip],f))
12016 new_return(15);
12017
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_extend],f))
12018 new_return(15);
12019 72 }
12020
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
12021 {
12022
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(medallionsprs[q][spr_tile],f))
12023 new_return(15);
12024
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
12025 new_return(15);
12026
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
12027 new_return(15);
12028 54 }
12029
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12030 {
12031
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimspr[q][spr_tile],f))
12032 new_return(16);
12033
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
12034 new_return(16);
12035
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
12036 new_return(16);
12037 72 }
12038
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12039 {
12040
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
12041 new_return(17);
12042
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
12043 new_return(17);
12044
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
12045 new_return(17);
12046 72 }
12047
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12048 {
12049
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
12050 new_return(17);
12051
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
12052 new_return(17);
12053
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
12054 new_return(17);
12055 72 }
12056
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12057 {
12058
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
12059 new_return(17);
12060
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
12061 new_return(17);
12062
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
12063 new_return(17);
12064 72 }
12065
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12066 {
12067
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
12068 new_return(18);
12069
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
12070 new_return(18);
12071
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
12072 new_return(18);
12073 72 }
12074
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12075 {
12076
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(hammeroffsets[q],f))
12077 new_return(19);
12078 72 }
12079
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q)
12080 {
12081
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12082 new_return(20);
12083
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12084 new_return(20);
12085
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12086 new_return(20);
12087 54 }
12088
12089
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12090 {
12091 new_return(21);
12092 }
12093
12094
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12095 {
12096 new_return(21);
12097 }
12098
12099
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12100 {
12101 new_return(21);
12102 }
12103
12104
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12105 {
12106
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12107 new_return(22);
12108
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12109 new_return(22);
12110
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12111 new_return(22);
12112 72 }
12113
12114
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
12115 {
12116
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(revslashspr[i][spr_tile],f))
12117 {
12118 new_return(23);
12119 }
12120
12121
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12122 {
12123 new_return(23);
12124 }
12125
12126
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12127 {
12128 new_return(23);
12129 }
12130 72 }
12131
12132
12133
2/2
✓ Branch 0 taken 2628 times.
✓ Branch 1 taken 18 times.
2646 for (int32_t q = 0; q < wMax; q++) // Hero defense values
12134 {
12135
1/2
✓ Branch 0 taken 2628 times.
✗ Branch 1 not taken.
2628 if (!p_putc(hero_defenses[q], f))
12136 new_return(15);
12137 2628 }
12138 //}
12139
12140
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12141 {
12142 9 section_size=writesize;
12143 9 }
12144 18 }
12145
12146 //More data will come here
12147
12148
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12149 {
12150 char ebuf[80];
12151 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12152 jwin_alert("Error: writeherosprites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12153 }
12154
12155 9 new_return(0);
12156 }
12157
12158 9 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12159 {
12160 9 dword section_id=ID_SUBSCREEN;
12161 9 dword section_version=V_SUBSCREEN;
12162 9 dword section_size=0;
12163
12164 //section id
12165
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
12166 {
12167 new_return(1);
12168 }
12169
12170 //section version info
12171
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
12172 {
12173 new_return(2);
12174 }
12175
12176
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
12177 {
12178 new_return(3);
12179 }
12180
12181
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12182 {
12183 18 fake_pack_writing=(writecycle==0);
12184
12185 //section size
12186
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
12187 {
12188 new_return(4);
12189 }
12190
12191 18 writesize=0;
12192
12193 18 byte sz = subscreens_active.size();
12194
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12195 new_return(5);
12196
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 18 times.
104 for(int32_t i=0; i<sz; i++)
12197 {
12198 86 int32_t ret = subscreens_active[i].write(f);
12199 86 fake_pack_writing=(writecycle==0);
12200
12201
1/2
✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
86 if(ret!=0)
12202 new_return(ret);
12203 86 }
12204
12205 18 sz = subscreens_passive.size();
12206
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12207 new_return(5);
12208
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 18 times.
82 for(int32_t i=0; i<sz; i++)
12209 {
12210 64 int32_t ret = subscreens_passive[i].write(f);
12211 64 fake_pack_writing=(writecycle==0);
12212
12213
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if(ret!=0)
12214 new_return(ret);
12215 64 }
12216
12217 18 sz = subscreens_overlay.size();
12218
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12219 new_return(5);
12220
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(int32_t i=0; i<sz; i++)
12221 {
12222 int32_t ret = subscreens_overlay[i].write(f);
12223 fake_pack_writing=(writecycle==0);
12224
12225 if(ret!=0)
12226 new_return(ret);
12227 }
12228
12229 18 sz = subscreens_map.size();
12230
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12231 new_return(5);
12232
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(int32_t i=0; i<sz; i++)
12233 {
12234 int32_t ret = subscreens_map[i].write(f);
12235 fake_pack_writing=(writecycle==0);
12236
12237 if(ret!=0)
12238 new_return(ret);
12239 }
12240
12241
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12242 {
12243 9 section_size=writesize;
12244 9 }
12245 18 }
12246
12247
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12248 {
12249 char ebuf[80];
12250 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12251 jwin_alert("Error: writesubscreens()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12252 }
12253
12254 9 new_return(0);
12255 9 }
12256
12257 extern script_data *ffscripts[NUMSCRIPTFFC];
12258 extern script_data *itemscripts[NUMSCRIPTITEM];
12259 extern script_data *guyscripts[NUMSCRIPTGUYS];
12260 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12261 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12262 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12263 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12264 extern script_data *playerscripts[NUMSCRIPTHERO];
12265 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12266 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12267 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12268 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12269 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12270
12271 9 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12272 {
12273
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
9 if (QMisc.zscript_last_compiled_version <= 26)
12274 3 return writeffscript_old(f, Header);
12275
12276 6 dword section_id = ID_FFSCRIPT;
12277 6 dword section_version = V_FFSCRIPT;
12278 6 dword section_size = 0;
12279 6 dword zasmmeta_version = METADATA_V;
12280 6 byte numscripts = 0;
12281 6 numscripts = numscripts; //to avoid unused variables warnings
12282
12283 //section id
12284
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12285 {
12286 new_return(1);
12287 }
12288
12289 //section version info
12290
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12291 {
12292 new_return(2);
12293 }
12294
12295
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!write_deprecated_section_cversion(section_version,f))
12296 {
12297 new_return(3);
12298 }
12299
12300
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12301 {
12302 new_return(4);
12303 }
12304
12305
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12306 {
12307 12 fake_pack_writing=(writecycle==0);
12308
12309 //section size
12310
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12311 {
12312 new_return(5);
12313 }
12314
12315 12 writesize=0;
12316
12317 12 write_quest_zasm(f);
12318
12319
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12320 {
12321 6144 int32_t ret = write_one_ffscript(f, Header, i, ffscripts[i]);
12322
12323
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12324 {
12325 new_return(ret);
12326 }
12327 6144 }
12328
12329
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12330 {
12331 3072 int32_t ret = write_one_ffscript(f, Header, i, itemscripts[i]);
12332
12333
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12334 {
12335 new_return(ret);
12336 }
12337 3072 }
12338
12339
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12340 {
12341 3072 int32_t ret = write_one_ffscript(f, Header, i, guyscripts[i]);
12342
12343
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12344 {
12345 new_return(ret);
12346 }
12347 3072 }
12348
12349
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12350
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12351 {
12352 3072 int32_t ret = write_one_ffscript(f, Header, i, fake);
12353
12354
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12355 {
12356 new_return(ret);
12357 }
12358 3072 }
12359
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12360
12361
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12362 {
12363 3072 int32_t ret = write_one_ffscript(f, Header, i, screenscripts[i]);
12364
12365
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12366 {
12367 new_return(ret);
12368 }
12369 3072 }
12370
12371
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12372 {
12373 96 int32_t ret = write_one_ffscript(f, Header, i, globalscripts[i]);
12374
12375
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12376 {
12377 new_return(ret);
12378 }
12379 96 }
12380
12381
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
12382 {
12383 60 int32_t ret = write_one_ffscript(f, Header, i, playerscripts[i]);
12384
12385
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12386 {
12387 new_return(ret);
12388 }
12389 60 }
12390
12391
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12392 {
12393 3072 int32_t ret = write_one_ffscript(f, Header, i, lwpnscripts[i]);
12394
12395
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12396 {
12397 new_return(ret);
12398 }
12399 3072 }
12400
12401
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12402 {
12403 3072 int32_t ret = write_one_ffscript(f, Header, i, ewpnscripts[i]);
12404
12405
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12406 {
12407 new_return(ret);
12408 }
12409 3072 }
12410
12411
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12412 {
12413 3072 int32_t ret = write_one_ffscript(f, Header, i, dmapscripts[i]);
12414
12415
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12416 {
12417 new_return(ret);
12418 }
12419 3072 }
12420
12421
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12422 {
12423 3072 int32_t ret = write_one_ffscript(f, Header, i, itemspritescripts[i]);
12424
12425
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12426 {
12427 new_return(ret);
12428 }
12429 3072 }
12430
12431
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12432 {
12433 6144 int32_t ret = write_one_ffscript(f, Header, i, comboscripts[i]);
12434
12435
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12436 {
12437 new_return(ret);
12438 }
12439 6144 }
12440
12441
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12442 {
12443 new_return(2000);
12444 }
12445
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12446 {
12447 6144 int32_t ret = write_one_ffscript(f, Header, i, genericscripts[i]);
12448
12449
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12450 {
12451 new_return(ret);
12452 }
12453 6144 }
12454
12455
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12456 {
12457 new_return(2001);
12458 }
12459
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12460 {
12461 3072 int32_t ret = write_one_ffscript(f, Header, i, subscreenscripts[i]);
12462
12463
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12464 {
12465 new_return(ret);
12466 }
12467 3072 }
12468
12469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12470 {
12471 new_return(2001);
12472 }
12473
12474
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12475 {
12476 new_return(2002);
12477 }
12478
12479 12 word numffcbindings=0;
12480
12481
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12482 {
12483
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12484 {
12485 158 numffcbindings++;
12486 158 }
12487 6132 }
12488
12489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12490 {
12491 new_return(2003);
12492 }
12493
12494
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12495 {
12496
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12497 {
12498
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputw(it->first,f))
12499 {
12500 new_return(2004);
12501 }
12502
12503
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12504 {
12505 new_return(2005);
12506 }
12507
12508
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12509 {
12510 new_return(2006);
12511 }
12512 158 }
12513 6132 }
12514
12515 12 word numglobalbindings=0;
12516
12517
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12518 {
12519
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12520 {
12521 22 numglobalbindings++;
12522 22 }
12523 96 }
12524
12525
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12526 {
12527 new_return(2007);
12528 }
12529
12530
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12531 {
12532
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12533 {
12534
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(it->first,f))
12535 {
12536 new_return(2008);
12537 }
12538
12539
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12540 {
12541 new_return(2009);
12542 }
12543
12544
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12545 {
12546 new_return(2010);
12547 }
12548 22 }
12549 96 }
12550
12551 12 word numitembindings=0;
12552
12553
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12554 {
12555
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12556 {
12557 26 numitembindings++;
12558 26 }
12559 3060 }
12560
12561
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12562 {
12563 new_return(2011);
12564 }
12565
12566
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12567 {
12568
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12569 {
12570
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(it->first,f))
12571 {
12572 new_return(2012);
12573 }
12574
12575
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12576 {
12577 new_return(2013);
12578 }
12579
12580
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12581 {
12582 new_return(2014);
12583 }
12584 26 }
12585 3060 }
12586
12587 //new script types
12588 //npc scripts
12589 12 word numnpcbindings=0;
12590
12591
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12592 {
12593
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12594 {
12595 numnpcbindings++;
12596 }
12597 3060 }
12598
12599
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12600 {
12601 new_return(2015);
12602 }
12603
12604
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12605 {
12606
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12607 {
12608 if(!p_iputw(it->first,f))
12609 {
12610 new_return(2016);
12611 }
12612
12613 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12614 {
12615 new_return(2017);
12616 }
12617
12618 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12619 {
12620 new_return(2018);
12621 }
12622 }
12623 3060 }
12624
12625 //lweapon
12626
12627 12 word numlwpnbindings=0;
12628
12629
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12630 {
12631
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12632 {
12633 2 numlwpnbindings++;
12634 2 }
12635 3060 }
12636
12637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12638 {
12639 new_return(2019);
12640 }
12641
12642
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12643 {
12644
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12645 {
12646
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12647 {
12648 new_return(2020);
12649 }
12650
12651
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12652 {
12653 new_return(2021);
12654 }
12655
12656
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12657 {
12658 new_return(2022);
12659 }
12660 2 }
12661 3060 }
12662
12663 //////
12664
12665 //eweapon
12666
12667
12668 12 word numewpnbindings=0;
12669
12670
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12671 {
12672
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12673 {
12674 numewpnbindings++;
12675 }
12676 3060 }
12677
12678
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12679 {
12680 new_return(2023);
12681 }
12682
12683
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12684 {
12685
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12686 {
12687 if(!p_iputw(it->first,f))
12688 {
12689 new_return(2024);
12690 }
12691
12692 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12693 {
12694 new_return(2025);
12695 }
12696
12697 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12698 {
12699 new_return(2026);
12700 }
12701 }
12702 3060 }
12703
12704 //player scripts
12705 12 word numherobindings=0;
12706
12707
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12708 {
12709
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12710 {
12711 numherobindings++;
12712 }
12713 48 }
12714
12715
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12716 {
12717 new_return(2027);
12718 }
12719
12720
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12721 {
12722
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12723 {
12724 if(!p_iputw(it->first,f))
12725 {
12726 new_return(2028);
12727 }
12728
12729 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12730 {
12731 new_return(2029);
12732 }
12733
12734 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12735 {
12736 new_return(2030);
12737 }
12738 }
12739 48 }
12740
12741 //dmap scripts
12742 12 word numdmapbindings=0;
12743
12744
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12745 {
12746
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12747 {
12748 10 numdmapbindings++;
12749 10 }
12750 3060 }
12751
12752
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12753 {
12754 new_return(2031);
12755 }
12756
12757
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12758 {
12759
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12760 {
12761
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(it->first,f))
12762 {
12763 new_return(2032);
12764 }
12765
12766
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12767 {
12768 new_return(2033);
12769 }
12770
12771
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12772 {
12773 new_return(2034);
12774 }
12775 10 }
12776 3060 }
12777
12778 //screen scripts
12779 12 word numscreenbindings=0;
12780
12781
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12782 {
12783
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12784 {
12785 4 numscreenbindings++;
12786 4 }
12787 3060 }
12788
12789
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12790 {
12791 new_return(2035);
12792 }
12793
12794
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12795 {
12796
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12797 {
12798
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12799 {
12800 new_return(2036);
12801 }
12802
12803
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12804 {
12805 new_return(2037);
12806 }
12807
12808
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12809 {
12810 new_return(2038);
12811 }
12812 4 }
12813 3060 }
12814 //item sprite scripts
12815 12 word numitemspritebindings=0;
12816
12817
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12818 {
12819
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12820 {
12821 numitemspritebindings++;
12822 }
12823 3060 }
12824
12825
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12826 {
12827 new_return(2039);
12828 }
12829
12830
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12831 {
12832
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12833 {
12834 if(!p_iputw(it->first,f))
12835 {
12836 new_return(2040);
12837 }
12838
12839 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12840 {
12841 new_return(2041);
12842 }
12843
12844 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12845 {
12846 new_return(2042);
12847 }
12848 }
12849 3060 }
12850
12851 //combo scripts
12852 12 word numcombobindings=0;
12853
12854
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12855 {
12856
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12857 {
12858 numcombobindings++;
12859 }
12860 6132 }
12861
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12862 {
12863 new_return(2043);
12864 }
12865
12866
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12867 {
12868
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12869 {
12870 if(!p_iputw(it->first,f))
12871 {
12872 new_return(2044);
12873 }
12874
12875 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12876 {
12877 new_return(2045);
12878 }
12879
12880 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12881 {
12882 new_return(2046);
12883 }
12884 }
12885 6132 }
12886 //subscreen scripts
12887 12 word numgenericbindings=0;
12888
12889
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12890 {
12891
2/2
✓ Branch 0 taken 6088 times.
✓ Branch 1 taken 44 times.
6132 if(it->second.scriptname != "")
12892 {
12893 44 numgenericbindings++;
12894 44 }
12895 6132 }
12896
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
12897 {
12898 new_return(2043);
12899 }
12900
12901
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12902 {
12903
2/2
✓ Branch 0 taken 6088 times.
✓ Branch 1 taken 44 times.
6132 if(it->second.scriptname != "")
12904 {
12905
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 if(!p_iputw(it->first,f))
12906 {
12907 new_return(2044);
12908 }
12909
12910
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12911 {
12912 new_return(2045);
12913 }
12914
12915
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12916 {
12917 new_return(2046);
12918 }
12919 44 }
12920 6132 }
12921
12922 //generic scripts
12923 12 word numsubscreenbindings=0;
12924
12925
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12926 {
12927
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12928 {
12929 numsubscreenbindings++;
12930 }
12931 3060 }
12932
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
12933 {
12934 new_return(2047);
12935 }
12936
12937
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12938 {
12939
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12940 {
12941 if(!p_iputw(it->first,f))
12942 {
12943 new_return(2048);
12944 }
12945
12946 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12947 {
12948 new_return(2049);
12949 }
12950
12951 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12952 {
12953 new_return(2050);
12954 }
12955 }
12956 3060 }
12957
12958
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12959 {
12960 6 section_size=writesize;
12961 6 }
12962 12 }
12963
12964
12965
12966
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12967 {
12968 char ebuf[80];
12969 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12970 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12971 }
12972
12973 6 new_return(0);
12974 //return 0; //this is just here to stomp the compiler from whining.
12975 //the irony is that it causes an "unreachable code" warning.
12976 9 }
12977
12978 12 int32_t write_quest_zasm(PACKFILE *f)
12979 {
12980 extern std::vector<std::shared_ptr<zasm_script>> zasm_scripts;
12981
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (zasm_scripts.empty())
12982 {
12983 if(!p_iputl(0,f))
12984 new_return(1);
12985
12986 return 0;
12987 }
12988
12989 12 auto& zasm = zasm_scripts[0]->zasm;
12990 12 size_t num_commands = zasm.size();
12991
12992
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(num_commands,f))
12993 new_return(1);
12994
12995
2/2
✓ Branch 0 taken 373324 times.
✓ Branch 1 taken 12 times.
373336 for(int32_t j=0; j<num_commands; j++)
12996 {
12997 373324 auto& zas = zasm[j];
12998
12999
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 373324 times.
373324 if(zas.command==0xFFFF)
13000 continue;
13001 else
13002 {
13003
1/2
✓ Branch 0 taken 373324 times.
✗ Branch 1 not taken.
373324 if(!p_iputw(zas.command,f))
13004 new_return(2);
13005
13006
1/2
✓ Branch 0 taken 373324 times.
✗ Branch 1 not taken.
373324 if(!p_iputl(zas.arg1,f))
13007 new_return(3);
13008
13009
1/2
✓ Branch 0 taken 373324 times.
✗ Branch 1 not taken.
373324 if(!p_iputl(zas.arg2,f))
13010 new_return(4);
13011
13012
1/2
✓ Branch 0 taken 373324 times.
✗ Branch 1 not taken.
373324 if(!p_iputl(zas.arg3,f))
13013 new_return(5);
13014
13015 373324 uint32_t sz = 0;
13016
2/2
✓ Branch 0 taken 372318 times.
✓ Branch 1 taken 1006 times.
373324 if(zas.strptr)
13017 1006 sz = zas.strptr->size();
13018
1/2
✓ Branch 0 taken 373324 times.
✗ Branch 1 not taken.
373324 if(!p_iputl(sz,f))
13019 new_return(6);
13020
2/2
✓ Branch 0 taken 372332 times.
✓ Branch 1 taken 992 times.
373324 if(sz)
13021 {
13022 992 auto& str = *zas.strptr;
13023
2/2
✓ Branch 0 taken 21172 times.
✓ Branch 1 taken 992 times.
22164 for(size_t q = 0; q < sz; ++q)
13024 {
13025
1/2
✓ Branch 0 taken 21172 times.
✗ Branch 1 not taken.
21172 if(!p_putc(str[q],f))
13026 new_return(7);
13027 21172 }
13028 992 }
13029 373324 sz = 0;
13030
2/2
✓ Branch 0 taken 373108 times.
✓ Branch 1 taken 216 times.
373324 if(zas.vecptr)
13031 216 sz = zas.vecptr->size();
13032
1/2
✓ Branch 0 taken 373324 times.
✗ Branch 1 not taken.
373324 if(!p_iputl(sz,f))
13033 new_return(8);
13034
2/2
✓ Branch 0 taken 373108 times.
✓ Branch 1 taken 216 times.
373324 if(sz) //vector found
13035 {
13036 216 auto& vec = *zas.vecptr;
13037
2/2
✓ Branch 0 taken 1312 times.
✓ Branch 1 taken 216 times.
1528 for(size_t q = 0; q < sz; ++q)
13038 {
13039
1/2
✓ Branch 0 taken 1312 times.
✗ Branch 1 not taken.
1312 if(!p_iputl(vec[q],f))
13040 new_return(9);
13041 1312 }
13042 216 }
13043 }
13044 373324 }
13045 12 return 0;
13046 12 }
13047
13048 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *, int32_t, script_data *script)
13049 {
13050
2/2
✓ Branch 0 taken 45984 times.
✓ Branch 1 taken 252 times.
46236 if (!script->valid())
13051 {
13052
1/2
✓ Branch 0 taken 45984 times.
✗ Branch 1 not taken.
45984 if (!p_putc(0, f))
13053 new_return(-1);
13054 45984 return 0;
13055 }
13056
13057
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if (!p_putc(1, f))
13058 new_return(-1);
13059
13060 252 zasm_meta const& tmeta = script->meta;
13061
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_iputw(tmeta.zasm_v,f))
13062 new_return(1);
13063
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_iputw(tmeta.meta_v,f))
13064 new_return(2);
13065
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_iputw(tmeta.ffscript_v,f))
13066 new_return(3);
13067
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_putc((int)tmeta.script_type,f))
13068 new_return(4);
13069
13070
2/2
✓ Branch 0 taken 2016 times.
✓ Branch 1 taken 252 times.
2268 for(int32_t q = 0; q < 8; ++q)
13071 {
13072
1/2
✓ Branch 0 taken 2016 times.
✗ Branch 1 not taken.
2016 if(!p_putcstr(tmeta.run_idens[q],f))
13073 new_return(5);
13074 2016 }
13075
13076
2/2
✓ Branch 0 taken 2016 times.
✓ Branch 1 taken 252 times.
2268 for(int32_t q = 0; q < 8; ++q)
13077
1/2
✓ Branch 0 taken 2016 times.
✗ Branch 1 not taken.
2016 if(!p_putc(tmeta.run_types[q],f))
13078 new_return(6);
13079
13080
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_putc(tmeta.flags,f))
13081 new_return(7);
13082
13083
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_iputw(tmeta.compiler_v1,f))
13084 new_return(8);
13085
13086
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_iputw(tmeta.compiler_v2,f))
13087 new_return(9);
13088
13089
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_iputw(tmeta.compiler_v3,f))
13090 new_return(10);
13091
13092
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_iputw(tmeta.compiler_v4,f))
13093 new_return(11);
13094
13095
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_putcstr(tmeta.script_name,f))
13096 new_return(12);
13097
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_putcstr(tmeta.author,f))
13098 new_return(13);
13099
2/2
✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 252 times.
2772 for(auto q = 0; q < 10; ++q)
13100 {
13101
1/2
✓ Branch 0 taken 2520 times.
✗ Branch 1 not taken.
2520 if(!p_putcstr(tmeta.attributes[q],f))
13102 new_return(14);
13103
1/2
✓ Branch 0 taken 2520 times.
✗ Branch 1 not taken.
2520 if(!p_putwstr(tmeta.attributes_help[q],f))
13104 new_return(15);
13105 2520 }
13106
2/2
✓ Branch 0 taken 2016 times.
✓ Branch 1 taken 252 times.
2268 for(auto q = 0; q < 8; ++q)
13107 {
13108
1/2
✓ Branch 0 taken 2016 times.
✗ Branch 1 not taken.
2016 if(!p_putcstr(tmeta.attribytes[q],f))
13109 new_return(16);
13110
1/2
✓ Branch 0 taken 2016 times.
✗ Branch 1 not taken.
2016 if(!p_putwstr(tmeta.attribytes_help[q],f))
13111 new_return(17);
13112 2016 }
13113
2/2
✓ Branch 0 taken 2016 times.
✓ Branch 1 taken 252 times.
2268 for(auto q = 0; q < 8; ++q)
13114 {
13115
1/2
✓ Branch 0 taken 2016 times.
✗ Branch 1 not taken.
2016 if(!p_putcstr(tmeta.attrishorts[q],f))
13116 new_return(18);
13117
1/2
✓ Branch 0 taken 2016 times.
✗ Branch 1 not taken.
2016 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13118 new_return(19);
13119 2016 }
13120
2/2
✓ Branch 0 taken 4032 times.
✓ Branch 1 taken 252 times.
4284 for(auto q = 0; q < 16; ++q)
13121 {
13122
1/2
✓ Branch 0 taken 4032 times.
✗ Branch 1 not taken.
4032 if(!p_putcstr(tmeta.usrflags[q],f))
13123 new_return(20);
13124
1/2
✓ Branch 0 taken 4032 times.
✗ Branch 1 not taken.
4032 if(!p_putwstr(tmeta.usrflags_help[q],f))
13125 new_return(21);
13126 4032 }
13127
2/2
✓ Branch 0 taken 2016 times.
✓ Branch 1 taken 252 times.
2268 for(auto q = 0; q < 8; ++q)
13128 {
13129
1/2
✓ Branch 0 taken 2016 times.
✗ Branch 1 not taken.
2016 if(!p_putcstr(tmeta.initd[q],f))
13130 new_return(22);
13131
1/2
✓ Branch 0 taken 2016 times.
✗ Branch 1 not taken.
2016 if(!p_putwstr(tmeta.initd_help[q],f))
13132 new_return(23);
13133 2016 }
13134
2/2
✓ Branch 0 taken 2016 times.
✓ Branch 1 taken 252 times.
2268 for(auto q = 0; q < 8; ++q)
13135 {
13136
1/2
✓ Branch 0 taken 2016 times.
✗ Branch 1 not taken.
2016 if(!p_putc(tmeta.initd_type[q],f))
13137 new_return(24);
13138 2016 }
13139
13140
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_iputl(script->pc, f))
13141 new_return(25);
13142
13143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!p_iputl(script->end_pc, f))
13144 new_return(26);
13145
13146 252 return 0;
13147 46236 }
13148
13149
13150 3 int32_t writeffscript_old(PACKFILE *f, zquestheader *Header)
13151 {
13152 3 dword section_id = ID_FFSCRIPT;
13153 3 dword section_version = 26;
13154 3 dword section_cversion = 1;
13155 3 dword section_size = 0;
13156 3 dword zasmmeta_version = 5;
13157 3 byte numscripts = 0;
13158 3 numscripts = numscripts; //to avoid unused variables warnings
13159
13160 //section id
13161
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_mputl(section_id,f))
13162 {
13163 new_return(1);
13164 }
13165
13166 //section version info
13167
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_version,f))
13168 {
13169 new_return(2);
13170 }
13171
13172
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_cversion,f))
13173 {
13174 new_return(3);
13175 }
13176
13177
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(zasmmeta_version,f))
13178 {
13179 new_return(4);
13180 }
13181
13182
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13183 {
13184 6 fake_pack_writing=(writecycle==0);
13185
13186 //section size
13187
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(section_size,f))
13188 {
13189 new_return(5);
13190 }
13191
13192 6 writesize=0;
13193
13194
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
13195 {
13196 3072 int32_t ret = write_one_ffscript_old(f, Header, i, ffscripts[i]);
13197 3072 fake_pack_writing=(writecycle==0);
13198
13199
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13200 {
13201 new_return(ret);
13202 }
13203 3072 }
13204
13205
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
13206 {
13207 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemscripts[i]);
13208 1536 fake_pack_writing=(writecycle==0);
13209
13210
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13211 {
13212 new_return(ret);
13213 }
13214 1536 }
13215
13216
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
13217 {
13218 1536 int32_t ret = write_one_ffscript_old(f, Header, i, guyscripts[i]);
13219 1536 fake_pack_writing=(writecycle==0);
13220
13221
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13222 {
13223 new_return(ret);
13224 }
13225 1536 }
13226
13227
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 script_data *fake = new script_data(ScriptType::None, 0);
13228
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13229 {
13230 1536 int32_t ret = write_one_ffscript_old(f, Header, i, fake);
13231 1536 fake_pack_writing=(writecycle==0);
13232
13233
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13234 {
13235 new_return(ret);
13236 }
13237 1536 }
13238
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 delete fake;
13239
13240
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
13241 {
13242 1536 int32_t ret = write_one_ffscript_old(f, Header, i, screenscripts[i]);
13243 1536 fake_pack_writing=(writecycle==0);
13244
13245
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13246 {
13247 new_return(ret);
13248 }
13249 1536 }
13250
13251
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
13252 {
13253 48 int32_t ret = write_one_ffscript_old(f, Header, i, globalscripts[i]);
13254 48 fake_pack_writing=(writecycle==0);
13255
13256
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(ret!=0)
13257 {
13258 new_return(ret);
13259 }
13260 48 }
13261
13262
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 6 times.
36 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
13263 {
13264 30 int32_t ret = write_one_ffscript_old(f, Header, i, playerscripts[i]);
13265 30 fake_pack_writing=(writecycle==0);
13266
13267
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(ret!=0)
13268 {
13269 new_return(ret);
13270 }
13271 30 }
13272
13273
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13274 {
13275 1536 int32_t ret = write_one_ffscript_old(f, Header, i, lwpnscripts[i]);
13276 1536 fake_pack_writing=(writecycle==0);
13277
13278
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13279 {
13280 new_return(ret);
13281 }
13282 1536 }
13283
13284
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13285 {
13286 1536 int32_t ret = write_one_ffscript_old(f, Header, i, ewpnscripts[i]);
13287 1536 fake_pack_writing=(writecycle==0);
13288
13289
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13290 {
13291 new_return(ret);
13292 }
13293 1536 }
13294
13295
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
13296 {
13297 1536 int32_t ret = write_one_ffscript_old(f, Header, i, dmapscripts[i]);
13298 1536 fake_pack_writing=(writecycle==0);
13299
13300
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13301 {
13302 new_return(ret);
13303 }
13304 1536 }
13305
13306
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
13307 {
13308 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemspritescripts[i]);
13309 1536 fake_pack_writing=(writecycle==0);
13310
13311
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13312 {
13313 new_return(ret);
13314 }
13315 1536 }
13316
13317
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
13318 {
13319 3072 int32_t ret = write_one_ffscript_old(f, Header, i, comboscripts[i]);
13320 3072 fake_pack_writing=(writecycle==0);
13321
13322
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13323 {
13324 new_return(ret);
13325 }
13326 3072 }
13327
13328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSGENERIC,f))
13329 {
13330 new_return(2000);
13331 }
13332
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
13333 {
13334 3072 int32_t ret = write_one_ffscript_old(f, Header, i, genericscripts[i]);
13335 3072 fake_pack_writing=(writecycle==0);
13336
13337
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13338 {
13339 new_return(ret);
13340 }
13341 3072 }
13342
13343
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
13344 {
13345 new_return(2001);
13346 }
13347
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
13348 {
13349 1536 int32_t ret = write_one_ffscript_old(f, Header, i, subscreenscripts[i]);
13350 1536 fake_pack_writing=(writecycle==0);
13351
13352
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13353 {
13354 new_return(ret);
13355 }
13356 1536 }
13357
13358
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl((int32_t)zScript.size(), f))
13359 {
13360 new_return(2001);
13361 }
13362
13363
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
13364 {
13365 new_return(2002);
13366 }
13367
13368 6 word numffcbindings=0;
13369
13370
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13371 {
13372
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13373 {
13374 206 numffcbindings++;
13375 206 }
13376 3066 }
13377
13378
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numffcbindings, f))
13379 {
13380 new_return(2003);
13381 }
13382
13383
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13384 {
13385
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13386 {
13387
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputw(it->first,f))
13388 {
13389 new_return(2004);
13390 }
13391
13392
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13393 {
13394 new_return(2005);
13395 }
13396
13397
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13398 {
13399 new_return(2006);
13400 }
13401 206 }
13402 3066 }
13403
13404 6 word numglobalbindings=0;
13405
13406
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13407 {
13408
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13409 {
13410 18 numglobalbindings++;
13411 18 }
13412 48 }
13413
13414
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numglobalbindings, f))
13415 {
13416 new_return(2007);
13417 }
13418
13419
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13420 {
13421
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13422 {
13423
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13424 {
13425 new_return(2008);
13426 }
13427
13428
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13429 {
13430 new_return(2009);
13431 }
13432
13433
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13434 {
13435 new_return(2010);
13436 }
13437 18 }
13438 48 }
13439
13440 6 word numitembindings=0;
13441
13442
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13443 {
13444
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13445 {
13446 18 numitembindings++;
13447 18 }
13448 1530 }
13449
13450
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitembindings, f))
13451 {
13452 new_return(2011);
13453 }
13454
13455
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13456 {
13457
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13458 {
13459
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13460 {
13461 new_return(2012);
13462 }
13463
13464
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13465 {
13466 new_return(2013);
13467 }
13468
13469
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13470 {
13471 new_return(2014);
13472 }
13473 18 }
13474 1530 }
13475
13476 //new script types
13477 //npc scripts
13478 6 word numnpcbindings=0;
13479
13480
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13481 {
13482
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13483 {
13484 numnpcbindings++;
13485 }
13486 1530 }
13487
13488
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numnpcbindings, f))
13489 {
13490 new_return(2015);
13491 }
13492
13493
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13494 {
13495
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13496 {
13497 if(!p_iputw(it->first,f))
13498 {
13499 new_return(2016);
13500 }
13501
13502 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13503 {
13504 new_return(2017);
13505 }
13506
13507 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13508 {
13509 new_return(2018);
13510 }
13511 }
13512 1530 }
13513
13514 //lweapon
13515
13516 6 word numlwpnbindings=0;
13517
13518
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13519 {
13520
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13521 {
13522 numlwpnbindings++;
13523 }
13524 1530 }
13525
13526
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numlwpnbindings, f))
13527 {
13528 new_return(2019);
13529 }
13530
13531
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13532 {
13533
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13534 {
13535 if(!p_iputw(it->first,f))
13536 {
13537 new_return(2020);
13538 }
13539
13540 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13541 {
13542 new_return(2021);
13543 }
13544
13545 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13546 {
13547 new_return(2022);
13548 }
13549 }
13550 1530 }
13551
13552 //////
13553
13554 //eweapon
13555
13556
13557 6 word numewpnbindings=0;
13558
13559
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13560 {
13561
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13562 {
13563 numewpnbindings++;
13564 }
13565 1530 }
13566
13567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numewpnbindings, f))
13568 {
13569 new_return(2023);
13570 }
13571
13572
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13573 {
13574
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13575 {
13576 if(!p_iputw(it->first,f))
13577 {
13578 new_return(2024);
13579 }
13580
13581 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13582 {
13583 new_return(2025);
13584 }
13585
13586 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13587 {
13588 new_return(2026);
13589 }
13590 }
13591 1530 }
13592
13593 //player scripts
13594 6 word numherobindings=0;
13595
13596
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13597 {
13598
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13599 {
13600 2 numherobindings++;
13601 2 }
13602 24 }
13603
13604
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numherobindings, f))
13605 {
13606 new_return(2027);
13607 }
13608
13609
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13610 {
13611
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13612 {
13613
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
13614 {
13615 new_return(2028);
13616 }
13617
13618
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13619 {
13620 new_return(2029);
13621 }
13622
13623
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13624 {
13625 new_return(2030);
13626 }
13627 2 }
13628 24 }
13629
13630 //dmap scripts
13631 6 word numdmapbindings=0;
13632
13633
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13634 {
13635
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13636 {
13637 numdmapbindings++;
13638 }
13639 1530 }
13640
13641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numdmapbindings, f))
13642 {
13643 new_return(2031);
13644 }
13645
13646
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13647 {
13648
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13649 {
13650 if(!p_iputw(it->first,f))
13651 {
13652 new_return(2032);
13653 }
13654
13655 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13656 {
13657 new_return(2033);
13658 }
13659
13660 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13661 {
13662 new_return(2034);
13663 }
13664 }
13665 1530 }
13666
13667 //screen scripts
13668 6 word numscreenbindings=0;
13669
13670
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13671 {
13672
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13673 {
13674 14 numscreenbindings++;
13675 14 }
13676 1530 }
13677
13678
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numscreenbindings, f))
13679 {
13680 new_return(2035);
13681 }
13682
13683
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13684 {
13685
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13686 {
13687
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputw(it->first,f))
13688 {
13689 new_return(2036);
13690 }
13691
13692
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13693 {
13694 new_return(2037);
13695 }
13696
13697
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13698 {
13699 new_return(2038);
13700 }
13701 14 }
13702 1530 }
13703 //item sprite scripts
13704 6 word numitemspritebindings=0;
13705
13706
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13707 {
13708
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13709 {
13710 numitemspritebindings++;
13711 }
13712 1530 }
13713
13714
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitemspritebindings, f))
13715 {
13716 new_return(2039);
13717 }
13718
13719
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13720 {
13721
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13722 {
13723 if(!p_iputw(it->first,f))
13724 {
13725 new_return(2040);
13726 }
13727
13728 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13729 {
13730 new_return(2041);
13731 }
13732
13733 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13734 {
13735 new_return(2042);
13736 }
13737 }
13738 1530 }
13739
13740 //combo scripts
13741 6 word numcombobindings=0;
13742
13743
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13744 {
13745
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13746 {
13747 numcombobindings++;
13748 }
13749 3066 }
13750
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numcombobindings, f))
13751 {
13752 new_return(2043);
13753 }
13754
13755
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13756 {
13757
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13758 {
13759 if(!p_iputw(it->first,f))
13760 {
13761 new_return(2044);
13762 }
13763
13764 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13765 {
13766 new_return(2045);
13767 }
13768
13769 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13770 {
13771 new_return(2046);
13772 }
13773 }
13774 3066 }
13775 //subscreen scripts
13776 6 word numgenericbindings=0;
13777
13778
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13779 {
13780
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13781 {
13782 numgenericbindings++;
13783 }
13784 3066 }
13785
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numgenericbindings, f))
13786 {
13787 new_return(2043);
13788 }
13789
13790
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13791 {
13792
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13793 {
13794 if(!p_iputw(it->first,f))
13795 {
13796 new_return(2044);
13797 }
13798
13799 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13800 {
13801 new_return(2045);
13802 }
13803
13804 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13805 {
13806 new_return(2046);
13807 }
13808 }
13809 3066 }
13810
13811 //generic scripts
13812 6 word numsubscreenbindings=0;
13813
13814
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13815 {
13816
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13817 {
13818 numsubscreenbindings++;
13819 }
13820 1530 }
13821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numsubscreenbindings, f))
13822 {
13823 new_return(2047);
13824 }
13825
13826
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13827 {
13828
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13829 {
13830 if(!p_iputw(it->first,f))
13831 {
13832 new_return(2048);
13833 }
13834
13835 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13836 {
13837 new_return(2049);
13838 }
13839
13840 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13841 {
13842 new_return(2050);
13843 }
13844 }
13845 1530 }
13846
13847
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if(writecycle==0)
13848 {
13849 3 section_size=writesize;
13850 3 }
13851 6 }
13852
13853
13854
13855
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if(writesize!=int32_t(section_size) && save_warn)
13856 {
13857 char ebuf[80];
13858 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13859 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13860 }
13861
13862 3 new_return(0);
13863 //return 0; //this is just here to stomp the compiler from whining.
13864 //the irony is that it causes an "unreachable code" warning.
13865 3 }
13866
13867 23118 int32_t write_one_ffscript_old(PACKFILE *f, zquestheader *Header, int32_t i, script_data *script)
13868 {
13869 //these are here to bypass compiler warnings about unused arguments
13870 23118 Header=Header;
13871 23118 i=i;
13872
13873
2/2
✓ Branch 0 taken 11830 times.
✓ Branch 1 taken 11288 times.
23118 size_t num_commands = script->zasm_script ? script->zasm_script->size : 0;
13874
13875
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputl(num_commands,f))
13876 {
13877 new_return(6);
13878 }
13879
13880 //Metadata
13881 23118 zasm_meta const& tmeta = script->meta;
13882
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.zasm_v,f))
13883 {
13884 new_return(7);
13885 }
13886
13887
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.meta_v,f))
13888 {
13889 new_return(8);
13890 }
13891
13892
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.ffscript_v,f))
13893 {
13894 new_return(9);
13895 }
13896
13897
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc((int)tmeta.script_type,f))
13898 {
13899 new_return(10);
13900 }
13901
13902
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13903 {
13904
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.run_idens[q],f))
13905 new_return(11);
13906 184944 }
13907
13908
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13909 {
13910
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.run_types[q],f))
13911 {
13912 new_return(12);
13913 }
13914 184944 }
13915
13916
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc(tmeta.flags,f))
13917 {
13918 new_return(13);
13919 }
13920
13921
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v1,f))
13922 {
13923 new_return(14);
13924 }
13925
13926
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v2,f))
13927 {
13928 new_return(15);
13929 }
13930
13931
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v3,f))
13932 {
13933 new_return(16);
13934 }
13935
13936
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v4,f))
13937 {
13938 new_return(17);
13939 }
13940
13941
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putcstr(tmeta.script_name,f))
13942 new_return(18);
13943
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23118 times.
23118 if(!p_putcstr(tmeta.author,f))
13944 new_return(19);
13945
2/2
✓ Branch 0 taken 231180 times.
✓ Branch 1 taken 23118 times.
254298 for(auto q = 0; q < 10; ++q)
13946 {
13947
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putcstr(tmeta.attributes[q],f))
13948 new_return(27);
13949
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putwstr(tmeta.attributes_help[q],f))
13950 new_return(28);
13951 231180 }
13952
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13953 {
13954
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attribytes[q],f))
13955 new_return(29);
13956
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attribytes_help[q],f))
13957 new_return(30);
13958 184944 }
13959
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13960 {
13961
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attrishorts[q],f))
13962 new_return(31);
13963
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13964 new_return(32);
13965 184944 }
13966
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 23118 times.
393006 for(auto q = 0; q < 16; ++q)
13967 {
13968
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.usrflags[q],f))
13969 new_return(33);
13970
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.usrflags_help[q],f))
13971 new_return(34);
13972 369888 }
13973
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13974 {
13975
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.initd[q],f))
13976 new_return(35);
13977
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.initd_help[q],f))
13978 new_return(36);
13979 184944 }
13980
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13981 {
13982
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.initd_type[q],f))
13983 new_return(37);
13984 184944 }
13985
13986
2/2
✓ Branch 0 taken 11288 times.
✓ Branch 1 taken 2056888 times.
2068176 for(int32_t j=0; j<num_commands; j++)
13987 {
13988 2056888 auto& zas = script->zasm_script->zasm[j];
13989
1/2
✓ Branch 0 taken 2056888 times.
✗ Branch 1 not taken.
2056888 if(!p_iputw(zas.command,f))
13990 {
13991 new_return(20);
13992 }
13993
13994
2/2
✓ Branch 0 taken 2045058 times.
✓ Branch 1 taken 11830 times.
2056888 if(zas.command==0xFFFF)
13995 {
13996 11830 break;
13997 }
13998 else
13999 {
14000
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg1,f))
14001 {
14002 new_return(21);
14003 }
14004
14005
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg2,f))
14006 {
14007 new_return(22);
14008 }
14009
14010
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg3,f))
14011 {
14012 new_return(23);
14013 }
14014
14015 2045058 uint32_t sz = 0;
14016
2/2
✓ Branch 0 taken 2340 times.
✓ Branch 1 taken 2042718 times.
2045058 if(zas.strptr)
14017 2340 sz = zas.strptr->size();
14018
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
14019 {
14020 new_return(23);
14021 }
14022
2/2
✓ Branch 0 taken 2042718 times.
✓ Branch 1 taken 2340 times.
2045058 if(sz)
14023 {
14024 2340 auto& str = *zas.strptr;
14025
2/2
✓ Branch 0 taken 214720 times.
✓ Branch 1 taken 2340 times.
217060 for(size_t q = 0; q < sz; ++q)
14026 {
14027
1/2
✓ Branch 0 taken 214720 times.
✗ Branch 1 not taken.
214720 if(!p_putc(str[q],f))
14028 {
14029 new_return(24);
14030 }
14031 214720 }
14032 2340 }
14033 2045058 sz = 0;
14034
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(zas.vecptr)
14035 22 sz = zas.vecptr->size();
14036
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
14037 {
14038 new_return(25);
14039 }
14040
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(sz) //vector found
14041 {
14042 22 auto& vec = *zas.vecptr;
14043
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 22 times.
374 for(size_t q = 0; q < sz; ++q)
14044 {
14045
1/2
✓ Branch 0 taken 352 times.
✗ Branch 1 not taken.
352 if(!p_iputl(vec[q],f))
14046 {
14047 new_return(26);
14048 }
14049 352 }
14050 22 }
14051 }
14052 2045058 }
14053
14054 23118 new_return(0);
14055 }
14056
14057 extern SAMPLE customsfxdata[WAV_COUNT];
14058 extern uint8_t customsfxflag[WAV_COUNT>>3];
14059
14060 9 int32_t writesfx(PACKFILE *f, zquestheader *Header)
14061 {
14062 //these are here to bypass compiler warnings about unused arguments
14063 9 Header=Header;
14064
14065 9 dword section_id=ID_SFX;
14066 9 dword section_version=V_SFX;
14067 9 dword section_size=0;
14068
14069 //section id
14070
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14071 {
14072 new_return(1);
14073 }
14074
14075 //section version info
14076
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14077 {
14078 new_return(2);
14079 }
14080
14081
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14082 {
14083 new_return(3);
14084 }
14085
14086
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14087 {
14088 18 fake_pack_writing=(writecycle==0);
14089
14090 //section size
14091
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14092 {
14093 new_return(4);
14094 }
14095
14096 18 writesize=0;
14097
14098
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int32_t i=0; i<WAV_COUNT>>3; i++)
14099 {
14100
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(customsfxflag[i],f))
14101 {
14102 new_return(5);
14103 }
14104 576 }
14105
14106
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14107 {
14108
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14109 3330 continue;
14110
14111
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!pfwrite(sfx_string[i], 36, f))
14112 {
14113 new_return(5);
14114 }
14115 1260 }
14116
14117
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14118 {
14119
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14120 3330 continue;
14121
14122
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].bits,f))
14123 {
14124 new_return(5);
14125 }
14126
14127
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].stereo,f))
14128 {
14129 new_return(6);
14130 }
14131
14132
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].freq,f))
14133 {
14134 new_return(7);
14135 }
14136
14137
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].priority,f))
14138 {
14139 new_return(8);
14140 }
14141
14142
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].len,f))
14143 {
14144 new_return(9);
14145 }
14146
14147
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_start,f))
14148 {
14149 new_return(10);
14150 }
14151
14152
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_end,f))
14153 {
14154 new_return(11);
14155 }
14156
14157
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].param,f))
14158 {
14159 new_return(12);
14160 }
14161
14162 //de-endianfy the data
14163 1260 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
14164
14165
2/2
✓ Branch 0 taken 28596352 times.
✓ Branch 1 taken 1260 times.
28597612 for(int32_t j=0; j<wordstowrite; j++)
14166 {
14167
1/2
✓ Branch 0 taken 28596352 times.
✗ Branch 1 not taken.
28596352 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
14168 {
14169 new_return(13);
14170 }
14171 28596352 }
14172 1260 }
14173
14174
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14175 {
14176 9 section_size=writesize;
14177 9 }
14178 18 }
14179
14180
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14181 {
14182 char ebuf[80];
14183 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14184 jwin_alert("Error: writesfx()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14185 }
14186
14187 9 new_return(0);
14188 }
14189
14190 9 int32_t writeinitdata(PACKFILE *f, zquestheader *)
14191 {
14192 9 dword section_id=ID_INITDATA;
14193 9 dword section_version=V_INITDATA;
14194 9 dword section_size = 0;
14195
14196 9 zinit.last_map=Map.getCurrMap();
14197 9 zinit.last_screen=Map.getCurrScr();
14198 9 zinit.normalize();
14199
14200 //section id
14201
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14202 {
14203 new_return(1);
14204 }
14205
14206 //section version info
14207
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14208 {
14209 new_return(2);
14210 }
14211
14212
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14213 {
14214 new_return(3);
14215 }
14216
14217 //TODO
14218
14219
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14220 {
14221 18 fake_pack_writing=(writecycle==0);
14222
14223 //section size
14224
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14225 new_return(4);
14226
14227 18 writesize=0;
14228
14229
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int q = 0; q < MAXITEMS/8; ++q)
14230
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(zinit.items[q], f))
14231 new_return(5);
14232
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int q = 0; q < MAXLEVELS; ++q)
14233 {
14234
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(zinit.litems[q], f))
14235 new_return(6);
14236 9216 }
14237
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbvec(zinit.level_keys, f))
14238 new_return(10);
14239
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(MAX_COUNTERS,f))
14240 new_return(11);
14241
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14242
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.counter[q],f))
14243 new_return(12);
14244
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14245
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.mcounter[q],f))
14246 new_return(13);
14247
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.bomb_ratio,f))
14248 new_return(14);
14249
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp,f))
14250 new_return(15);
14251
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp_per_hc,f))
14252 new_return(16);
14253
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.cont_heart,f))
14254 new_return(17);
14255
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hp_per_heart,f))
14256 new_return(18);
14257
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magic_per_block,f))
14258 new_return(19);
14259
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_damage_multiplier,f))
14260 new_return(20);
14261
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.ene_damage_multiplier,f))
14262 new_return(21);
14263
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_type,f))
14264 new_return(22);
14265
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_arg,f))
14266 new_return(23);
14267
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_percent,f))
14268 new_return(24);
14269
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.def_lightrad,f))
14270 new_return(25);
14271
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.transdark_percent,f))
14272 new_return(26);
14273
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.darkcol,f))
14274 new_return(27);
14275
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_x,f))
14276 new_return(28);
14277
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_y,f))
14278 new_return(29);
14279
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_xofs,f))
14280 new_return(30);
14281
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_yofs,f))
14282 new_return(31);
14283
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_color,f))
14284 new_return(32);
14285
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_1_color,f))
14286 new_return(33);
14287
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_2_color,f))
14288 new_return(34);
14289
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_flags,f))
14290 new_return(35);
14291
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.flags,f))
14292 new_return(36);
14293
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_map,f))
14294 new_return(37);
14295
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_screen,f))
14296 new_return(38);
14297
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_x,f))
14298 new_return(39);
14299
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_y,f))
14300 new_return(40);
14301
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_is_offset,f))
14302 new_return(41);
14303
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_speed,f))
14304 new_return(42);
14305
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.gravity,f))
14306 new_return(43);
14307
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.swimgravity,f))
14308 new_return(44);
14309
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.terminalv,f))
14310 new_return(45);
14311
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_speed,f))
14312 new_return(46);
14313
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_mult,f))
14314 new_return(47);
14315
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_div,f))
14316 new_return(48);
14317
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimUpStep,f))
14318 new_return(49);
14319
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimSideStep,f))
14320 new_return(50);
14321
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimDownStep,f))
14322 new_return(51);
14323
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.exitWaterJump,f))
14324 new_return(52);
14325
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroStep,f))
14326 new_return(53);
14327
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.heroAnimationStyle,f))
14328 new_return(54);
14329
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.jump_hero_layer_threshold,f))
14330 new_return(55);
14331
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.bunny_ltm,f))
14332 new_return(56);
14333
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.start_dmap,f))
14334 new_return(57);
14335
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.subscrSpeed,f))
14336 new_return(58);
14337
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.switchhookstyle,f))
14338 new_return(59);
14339
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magicdrainrate,f))
14340 new_return(60);
14341
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputzf(zinit.shove_offset,f))
14342 new_return(61);
14343
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.gen_doscript, f))
14344 new_return(62);
14345
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_exitState, f))
14346 new_return(63);
14347
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_reloadState, f))
14348 new_return(64);
14349
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_initd, f))
14350 new_return(65);
14351
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_eventstate, f))
14352 new_return(66);
14353
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_data, f))
14354 new_return(67);
14355
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.screen_data, f))
14356 new_return(68);
14357
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickerspeed, f))
14358 new_return(69);
14359
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickercolor, f))
14360 new_return(70);
14361
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickertransp, f))
14362 new_return(71);
14363
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputzf(zinit.air_drag, f))
14364 new_return(72);
14365
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_rate, f))
14366 new_return(73);
14367
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_size, f))
14368 new_return(74);
14369
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.region_mapping, f))
14370 new_return(75);
14371
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(uint q = 0; q < NUM_BOTTLE_SLOTS; ++q)
14372
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!p_putc(zinit.bottle_slot[q], f))
14373 new_return(76);
14374
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putbvec(zinit.lvlswitches, f))
14375 new_return(77);
14376
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_spawn_flicker, f))
14377 new_return(78);
14378
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_dur, f))
14379 new_return(79);
14380
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_flicker, f))
14381 new_return(80);
14382
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.item_flicker_speed, f))
14383 new_return(81);
14384
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 18 times.
108 for(int q = 0; q < SPRITE_THRESHOLD_MAX; ++q)
14385
1/2
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
90 if (!p_iputw(zinit.sprite_z_thresholds[q], f))
14386 new_return(82);
14387
14388
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14389 {
14390 9 section_size=writesize;
14391 9 }
14392 18 }
14393
14394
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14395 {
14396 char ebuf[80];
14397 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14398 jwin_alert("Error: writeinitdata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14399 }
14400
14401 9 new_return(0);
14402 }
14403
14404 9 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
14405 {
14406 //these are here to bypass compiler warnings about unused arguments
14407 9 Header=Header;
14408
14409 9 dword section_id=ID_ITEMDROPSETS;
14410 9 dword section_version=V_ITEMDROPSETS;
14411 // dword section_size=0;
14412 9 dword section_size = 0;
14413 9 word num_item_drop_sets=count_item_drop_sets();
14414
14415 //section id
14416
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14417 {
14418 new_return(1);
14419 }
14420
14421 //section version info
14422
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14423 {
14424 new_return(2);
14425 }
14426
14427
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14428 {
14429 new_return(3);
14430 }
14431
14432
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14433 {
14434 18 fake_pack_writing=(writecycle==0);
14435
14436 //section size
14437
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14438 {
14439 new_return(4);
14440 }
14441
14442 18 writesize=0;
14443
14444 //finally... section data
14445
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_item_drop_sets,f))
14446 {
14447 new_return(5);
14448 }
14449
14450
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 18 times.
254 for(int32_t i=0; i<num_item_drop_sets; i++)
14451 {
14452
1/2
✓ Branch 0 taken 236 times.
✗ Branch 1 not taken.
236 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
14453 {
14454 new_return(6);
14455 }
14456
14457
2/2
✓ Branch 0 taken 2360 times.
✓ Branch 1 taken 236 times.
2596 for(int32_t j=0; j<10; ++j)
14458 {
14459
1/2
✓ Branch 0 taken 2360 times.
✗ Branch 1 not taken.
2360 if(!p_iputw(item_drop_sets[i].item[j],f))
14460 {
14461 new_return(7);
14462 }
14463 2360 }
14464
14465
2/2
✓ Branch 0 taken 2596 times.
✓ Branch 1 taken 236 times.
2832 for(int32_t j=0; j<11; ++j)
14466 {
14467
1/2
✓ Branch 0 taken 2596 times.
✗ Branch 1 not taken.
2596 if(!p_iputw(item_drop_sets[i].chance[j],f))
14468 {
14469 new_return(8);
14470 }
14471 2596 }
14472 236 }
14473
14474
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14475 {
14476 9 section_size=writesize;
14477 9 }
14478 18 }
14479
14480
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14481 {
14482 char ebuf[80];
14483 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14484 jwin_alert("Error: writeitemdropsets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14485 }
14486
14487 9 new_return(0);
14488 }
14489
14490 9 int32_t writefavorites(PACKFILE *f, zquestheader*)
14491 {
14492 9 dword section_id=ID_FAVORITES;
14493 9 dword section_version=V_FAVORITES;
14494 9 dword section_size = 0;
14495
14496 //section id
14497
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14498 {
14499 new_return(1);
14500 }
14501
14502 //section version info
14503
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14504 {
14505 new_return(2);
14506 }
14507
14508
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14509 {
14510 new_return(3);
14511 }
14512
14513
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14514 {
14515 18 fake_pack_writing=(writecycle==0);
14516
14517 //section size
14518
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14519 new_return(4);
14520
14521 18 writesize=0;
14522
14523
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
14524 new_return(16);
14525
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
14526 new_return(17);
14527
14528 18 word favcmb_cnt = 0;
14529
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 22234 times.
22238 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
14530
2/2
✓ Branch 0 taken 22220 times.
✓ Branch 1 taken 14 times.
22234 if(favorite_combos[q] != -1)
14531 {
14532 14 favcmb_cnt = q+1;
14533 14 break;
14534 }
14535
14536
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
14537 new_return(5);
14538
14539
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 18 times.
478 for(int i=0; i<favcmb_cnt; ++i)
14540 {
14541
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_putc(favorite_combo_modes[i], f))
14542 new_return(6);
14543
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputl(favorite_combos[i], f))
14544 new_return(7);
14545 460 }
14546
14547
14548 18 word max_combo_cols = MAX_COMBO_COLS;
14549
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_combo_cols,f))
14550 new_return(9);
14551
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int q = 0; q < max_combo_cols; ++q)
14552 {
14553
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(First[q],f))
14554 new_return(10);
14555
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_alistpos[q],f))
14556 new_return(11);
14557
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_pool_listpos[q],f))
14558 new_return(12);
14559 72 }
14560 18 word max_mappages = MAX_MAPPAGE_BTNS;
14561
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_mappages,f))
14562 new_return(13);
14563
2/2
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 18 times.
180 for(int q = 0; q < max_mappages; ++q)
14564 {
14565
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].map,f))
14566 new_return(14);
14567
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].screen,f))
14568 new_return(15);
14569 162 }
14570
14571
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14572 {
14573 9 section_size=writesize;
14574 9 }
14575 18 }
14576
14577
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14578 {
14579 char ebuf[80];
14580 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14581 jwin_alert("Error: writefavorites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14582 }
14583
14584 9 new_return(0);
14585 }
14586
14587 9 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
14588 {
14589
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!afname) afname = filename;
14590 9 reset_combo_animations();
14591 9 reset_combo_animations2();
14592 9 strcpy(header.id_str,QH_NEWIDSTR);
14593 9 header.zelda_version = ZELDA_VERSION;
14594 9 header.internal = INTERNAL_VERSION;
14595 9 header.data_flags[ZQ_TILES] = true;
14596 9 header.data_flags[ZQ_CHEATS2] = 1;
14597 9 header.build=VERSION_BUILD;
14598
14599
2/2
✓ Branch 0 taken 2268 times.
✓ Branch 1 taken 9 times.
2277 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
14600 {
14601 2268 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
14602 2268 }
14603
14604 char zinfofilename[2048];
14605 9 replace_extension(zinfofilename, afname, "zinfo", 2047);
14606
14607 9 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
14608 9 box_out("Saving Quest...");
14609 9 box_eol();
14610 9 box_eol();
14611
14612
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 std::string tmp_filename = util::create_temp_file_path(filename);
14613
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
14614
14615
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!f)
14616 return 1;
14617
14618
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Header...");
14619
14620
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeheader(f,&header)!=0)
14621 return 2;
14622
14623
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14624
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14625
14626
14627
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(header.external_zinfo)
14628 {
14629 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
14630
14631 box_out("Writing ZInfo...");
14632 if(inf)
14633 {
14634 if(writezinfo(inf,ZI)!=0)
14635 return 2;
14636
14637 pack_fclose(inf);
14638 box_out("okay.");
14639 }
14640 else box_out(" ...file failure");
14641 box_eol();
14642 }
14643 else
14644 {
14645
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing ZInfo...");
14646
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writezinfo(f,ZI)!=0)
14647 return 2;
14648
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14649
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14650 }
14651
14652
14653
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Rules...");
14654
14655
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writerules(f,&header)!=0)
14656 return 3;
14657
14658
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14659
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14660
14661
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Strings...");
14662
14663
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
14664 return 4;
14665
14666
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14667
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14668
14669
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Doors...");
14670
14671
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedoorcombosets(f,&header)!=0)
14672 return 5;
14673
14674
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14675
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14676
14677
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing DMaps...");
14678
14679
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
14680 return 6;
14681
14682
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14683
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14684
14685
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Data...");
14686
14687
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemisc(f,&header)!=0)
14688 return 7;
14689
14690
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14691
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14692
14693
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Colors...");
14694
14695
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemisccolors(f,&header)!=0)
14696 return 8;
14697
14698
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14699
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14700
14701
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Game Icons...");
14702
14703
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writegameicons(f,&header)!=0)
14704 return 9;
14705
14706
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14707
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14708
14709
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Items...");
14710
14711
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeitems(f,&header)!=0)
14712 return 10;
14713
14714
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14715
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14716
14717
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Weapons...");
14718
14719
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeweapons(f,&header)!=0)
14720 return 11;
14721
14722
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14723
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14724
14725
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Maps...");
14726
14727
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemaps(f,&header)!=0)
14728 return 12;
14729
14730
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14731
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14732
14733
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combos...");
14734
14735
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
14736 return 13;
14737
14738
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14739
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14740
14741
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combo Aliases...");
14742
14743
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
14744 return 14;
14745
14746
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14747
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14748
14749
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Color Data...");
14750
14751
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
14752 return 15;
14753
14754
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14755
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14756
14757
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Tiles...");
14758
14759
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
14760 return 16;
14761
14762
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14763
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14764
14765
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing MIDIs...");
14766
14767
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemidis(f)!=0)
14768 return 17;
14769
14770
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14771
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14772
14773
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Cheat Codes...");
14774
14775
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecheats(f,&header)!=0)
14776 return 18;
14777
14778
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14779
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14780
14781
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Init. Data...");
14782
14783
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeinitdata(f,&header)!=0)
14784 return 19;
14785
14786
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14787
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14788
14789
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Guy Data...");
14790
14791
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeguys(f,&header)!=0)
14792 return 20;
14793
14794
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14795
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14796
14797
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Hero Sprite Data...");
14798
14799
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeherosprites(f,&header)!=0)
14800 return 21;
14801
14802
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14803
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14804
14805
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Subscreen Data...");
14806
14807
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesubscreens(f,&header)!=0)
14808 return 22;
14809
14810
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14811
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14812
14813
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing FF Script Data...");
14814
14815
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeffscript(f,&header)!=0)
14816 return 23;
14817
14818
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14819
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14820
14821
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing SFX Data...");
14822
14823
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesfx(f,&header)!=0)
14824 return 24;
14825
14826
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14827
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14828
14829
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Item Drop Sets...");
14830
14831
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeitemdropsets(f, &header)!=0)
14832 return 25;
14833
14834
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14835
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14836
14837
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Favorite Combos...");
14838
14839
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writefavorites(f, &header)!=0)
14840 return 26;
14841
14842
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14843
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14844
14845
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 pack_fclose(f);
14846
14847
14848
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
9 if(header.use_keyfile&&header.dirty_password)
14849 {
14850 char const* kfname = filename;
14851 char keyfilename[2048]={0};
14852 zprint2("Writing key files for '%s'\n", kfname);
14853
14854 char temp_pw[QSTPWD_LEN] = {0};
14855 uint ind = 0;
14856 for(char const* ext : {"key","zpwd","zcheat"})
14857 {
14858 replace_extension(keyfilename, kfname, ext, 2047);
14859 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
14860 char msg[80] = {0};
14861 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
14862 msg[78]=13;
14863 msg[79]=10;
14864 pfwrite(msg, 80, fp);
14865 p_iputw(header.zelda_version,fp);
14866 p_putc(header.build,fp);
14867 char const* pwd = header.password;
14868 if(ind == 2) //.zcheat, hashed pwd
14869 {
14870 char hashmap = 'Z';
14871 hashmap += 'Q';
14872 hashmap += 'U';
14873 hashmap += 'E';
14874 hashmap += 'S';
14875 hashmap += 'T';
14876 for ( int q = 0; q < QSTPWD_LEN; ++q )
14877 {
14878 temp_pw[q] = header.password[q];
14879 temp_pw[q] += hashmap;
14880 }
14881 pwd = temp_pw;
14882 }
14883 pfwrite(pwd, strlen(pwd), fp);
14884 pack_fclose(fp);
14885 ++ind;
14886 }
14887 }
14888
14889 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
14890 9 std::error_code ec;
14891
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 fs::rename(tmp_filename, filename, ec);
14892
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ec)
14893 {
14894 al_trace("Error saving: %s\n", std::strerror(ec.value()));
14895 return ec.value();
14896 }
14897
14898
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
14899
14900 #ifdef __EMSCRIPTEN__
14901 em_sync_fs();
14902 #endif
14903
14904 9 return 0;
14905 9 }
14906
14907 // #ifdef _WIN32
14908 // static std::time_t to_time_t(FILETIME const& ft) {
14909 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14910 // t -= 116444736000000000ull;
14911 // t /= 10000000u;
14912 // return static_cast<std::time_t>(t);
14913 // }
14914 // #else
14915 // #endif
14916 template<typename TP>
14917 6 static std::time_t to_time_t(TP tp) {
14918 using namespace std::chrono;
14919 6 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14920 6 return system_clock::to_time_t(sctp);
14921 }
14922
14923 6 std::string get_time_last_modified_string(std::string path)
14924 {
14925
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 auto write_time = fs::last_write_time(path);
14926 // TODO: C++20 but not supported yet.
14927 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14928 6 std::time_t tt = to_time_t(write_time);
14929 6 std::tm *gmt = std::gmtime(&tt);
14930 6 std::stringstream buffer;
14931
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 buffer << std::put_time(gmt, "%Y-%m-%d");
14932
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 std::string formattedFileTime = buffer.str();
14933 6 return formattedFileTime;
14934
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 }
14935
14936 9 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14937 {
14938 // Always backup quest if it was last saved in a different version of the editor,
14939 // or if this a new file and is overwritting another qst file.
14940
10/16
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 6 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
9 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14941 {
14942 6 std::string backup_name;
14943
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 std::string last_mod = get_time_last_modified_string(filename);
14944
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (strlen(header.zelda_version_string) > 0)
14945 {
14946
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14947 6 }
14948 else
14949 {
14950 backup_name = fmt::format("{}", last_mod);
14951 }
14952
7/14
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
6 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14953
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 fs::path backup_path = fs::path("backups") / backup_fname;
14954
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if (!fs::exists(backup_path))
14955 {
14956
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 fs::create_directories(fs::path("backups"));
14957
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 if (fs::copy_file(filename, backup_path))
14958 {
14959
5/10
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 6 times.
6 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14960 6 }
14961 else
14962 {
14963 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14964 }
14965 6 }
14966 6 }
14967
14968 9 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14969 9 fake_pack_writing = false;
14970
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret)
14971 {
14972 box_out("-- Error saving quest file! --");
14973 box_end(true);
14974 }
14975 9 else box_end(false);
14976 9 return ret;
14977 }
14978
14979 9 int32_t save_quest(const char *filename, bool timed_save)
14980 {
14981
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14982
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 bool compress=!(timed_save&&UncompressedAutoSaves);
14983 char ext1[5];
14984 9 ext1[0]=0;
14985
14986
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(timed_save)
14987 {
14988 sprintf(ext1, "qt");
14989 }
14990 else
14991 {
14992 9 sprintf(ext1, "qb");
14993 }
14994
14995
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(retention)
14996 {
14997 char backupname[2048];
14998 char backupname2[2048];
14999 char ext[12];
15000
15001 for(int32_t i=retention-1; i>0; --i)
15002 {
15003 sprintf(ext, "%s%d", ext1, i-1);
15004 replace_extension(backupname, filepath, ext, 2047);
15005
15006 if(exists(backupname))
15007 {
15008 sprintf(ext, "%s%d", ext1, i);
15009 replace_extension(backupname2, filepath, ext, 2047);
15010
15011 if(exists(backupname2))
15012 {
15013 remove(backupname2);
15014 }
15015
15016 rename(backupname, backupname2);
15017 }
15018 }
15019
15020 //don't do this if we're not saving to the same name -DD
15021 if(!timed_save && !strcmp(filepath, filename))
15022 {
15023 sprintf(ext, "%s%d", ext1, 0);
15024 replace_extension(backupname, filepath, ext, 2047);
15025 rename(filepath, backupname);
15026 }
15027 }
15028
15029 int32_t ret;
15030 9 ret = save_unencoded_quest(filename, compress, filename);
15031
15032 9 return ret;
15033 }
15034
15035 1 void center_zq_class_dialogs()
15036 {
15037 1 jwin_center_dialog(pwd_dlg);
15038 1 }
15039
15040 void zmap::prv_secrets(bool high16only)
15041 {
15042 mapscr *s = &prvscr;
15043 mapscr *t = prvlayers;
15044 int32_t ft=0;
15045
15046 for(int32_t i=0; i<176; i++)
15047 {
15048 if(!high16only)
15049 {
15050 for(int32_t j=-1; j<6; j++)
15051 {
15052 int32_t newflag = -1;
15053
15054 for(int32_t iter=0; iter<2; ++iter)
15055 {
15056 if(!t[j].valid)
15057 continue;
15058
15059 int32_t checkflag=combobuf[t[j].data[i]].flag;
15060
15061 if(iter==1)
15062 {
15063 checkflag=t[j].sflag[i];
15064 }
15065
15066 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
15067 if (ft != -1)
15068 {
15069 if(j==-1)
15070 {
15071 s->data[i] = s->secretcombo[ft];
15072 s->cset[i] = s->secretcset[ft];
15073 newflag = s->secretflag[ft];
15074 }
15075 else
15076 {
15077 t[j].data[i] = t[j].secretcombo[ft];
15078 t[j].cset[i] = t[j].secretcset[ft];
15079 newflag = t[j].secretflag[ft];
15080 }
15081 }
15082 }
15083
15084 if(newflag >-1)
15085 {
15086 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
15087 }
15088 }
15089 }
15090
15091 //if(true)
15092 //{
15093 int32_t newflag = -1;
15094
15095 for(int32_t iter=0; iter<2; ++iter)
15096 {
15097 int32_t checkflag=combobuf[s->data[i]].flag;
15098
15099 if(iter==1)
15100 {
15101 checkflag=s->sflag[i];
15102 }
15103
15104 if((checkflag > 15)&&(checkflag < 32))
15105 {
15106 s->data[i] = s->secretcombo[(checkflag)-16+4];
15107 s->cset[i] = s->secretcset[(checkflag)-16+4];
15108 newflag = s->secretflag[(checkflag)-16+4];
15109 // putit = true;
15110 }
15111 }
15112
15113 if(newflag >-1) s->sflag[i] = newflag;
15114
15115 for(int32_t j=0; j<6; j++)
15116 {
15117 if(!t[j].valid) continue;
15118
15119 int32_t newflag2 = -1;
15120
15121 for(int32_t iter=0; iter<2; ++iter)
15122 {
15123 int32_t checkflag=combobuf[t[j].data[i]].flag;
15124
15125 if(iter==1)
15126 {
15127 checkflag=t[j].sflag[i];
15128 }
15129
15130 if((checkflag > 15)&&(checkflag < 32))
15131 {
15132 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
15133 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
15134 newflag2 = t[j].secretflag[(checkflag)-16+4];
15135 }
15136 }
15137
15138 if(newflag2 >-1) t[j].sflag[i] = newflag2;
15139 }
15140 }
15141
15142 //FFCs
15143 word num_ffcs = s->numFFC();
15144 for(word i=0; i<num_ffcs; ++i)
15145 {
15146 if(!high16only)
15147 {
15148 for(int32_t iter=0; iter<1; ++iter)
15149 {
15150 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15151
15152 if(iter==1)
15153 {
15154 checkflag=s->sflag[i];
15155 }
15156
15157 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
15158 if (ft != -1)
15159 {
15160 s->ffcs[i].data = s->secretcombo[ft];
15161 s->ffcs[i].cset = s->secretcset[ft];
15162 }
15163 }
15164 }
15165
15166 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
15167 {
15168 for(int32_t iter=0; iter<1; ++iter)
15169 {
15170 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15171
15172 if(iter==1)
15173 {
15174 // FFCs can't have flags! Yet...
15175 }
15176
15177 if((checkflag > 15)&&(checkflag < 32))
15178 {
15179 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
15180 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
15181 }
15182 }
15183 }
15184 }
15185 }
15186